Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 import csv
- 2 from lxml import html
- 3 import requests
- 4
- 5 with open('wa.csv','wb') as csvfile:
- 6 writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
- 7
- 8 page = requests.get('http://www.webassign.net/features/textbooks/mathematics_textbooks.html')
- 9 tree = html.fromstring(page.content)
- 10
- 11 books = tree.xpath('//table[@class="textbooks"]')
- 12 books = books[0]
- 13
- 14 rows = books.findall('tr')
- 15 for row in rows[1:]:
- 16 cells = row.findall('td')
- 17 title = cells[1].find('p').find('a').text_content()
- 18 print title
- 19
- 20 author = cells[2].text_content()
- 21 print author
- 22
- 23 publisher = cells[3].text_content()
- 24 print publisher
- 25
- 26 num_questions = cells[4].find('p').text_content()
- 27 print num_questions
- 28
- 29 writer.writerow([title, author, publisher, num_questions])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement