Advertisement
Guest User

Untitled

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