Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- import requests
- req = requests.get("http://www.elections.ca/WPAPPS/WPR/EN/NC/Details?province=-1&distyear=2013&district=-1&party=-1&selectedid=8548")
- page_source = BeautifulSoup(req.text, "html.parser")
- table = page_source.find("table",{"id":"gvContestants/1"})
- for row in table.find_all("tr"):
- if not row.find("img"):
- continue
- if "selected_box.gif" in row.find("img").get("src"):
- print(''.join(row.find("td",{"headers":"name/1"}).text.split()))
- output:
- Traceback (most recent call last):
- File "/home/martin/dev/python/elections_california.py", line 6, in <module>
- for row in table.find_all("tr"):
- AttributeError: 'NoneType' object has no attribute 'find_all'
- [Finished in 1.37s]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement