SHARE
TWEET

bs4_request_6

a guest Mar 27th, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. from bs4 import BeautifulSoup
  4. import requests
  5. req  = requests.get("http://www.elections.ca/WPAPPS/WPR/EN/NC/Details?province=-1&distyear=2013&district=-1&party=-1&selectedid=8548")
  6. page_source = BeautifulSoup(req.text, "html.parser")
  7. table = page_source.find("table",{"id":"gvContestants/1"})
  8. for row in table.find_all("tr"):
  9.     if not row.find("img"):
  10.         continue
  11.     if "selected_box.gif" in row.find("img").get("src"):
  12.         print(''.join(row.find("td",{"headers":"name/1"}).text.split()))
  13.  
  14.  
  15. output:
  16.  
  17. Traceback (most recent call last):
  18.   File "/home/martin/dev/python/elections_california.py", line 6, in <module>
  19.     for row in table.find_all("tr"):
  20. AttributeError: 'NoneType' object has no attribute 'find_all'
  21. [Finished in 1.37s]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top