Advertisement
Guest User

bs4_request_2

a guest
Mar 27th, 2020
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import pandas as pd
  4.  
  5. list = ['https://ballotpedia.org/Alabama_Supreme_Court',
  6. 'https://ballotpedia.org/Alaska_Supreme_Court',
  7. 'https://ballotpedia.org/Arizona_Supreme_Court',
  8. 'https://ballotpedia.org/Arkansas_Supreme_Court',
  9. 'https://ballotpedia.org/California_Supreme_Court',
  10. 'https://ballotpedia.org/Colorado_Supreme_Court',
  11. 'https://ballotpedia.org/Connecticut_Supreme_Court',
  12. 'https://ballotpedia.org/Delaware_Supreme_Court']
  13.  
  14. temp_dict = {}
  15.  
  16. for page in list:
  17. r = requests.get(page)
  18. soup = BeautifulSoup(r.content, 'html.parser')
  19.  
  20. temp_dict[page.split('/')[-1]] = [item.text for item in
  21. soup.select("table.wikitable.sortable.jquery-
  22. tablesorter a")]
  23.  
  24. df = pd.DataFrame.from_dict(temp_dict,
  25. orient='index').transpose()
  26. df.to_csv('State Supreme Court Justices.csv')
  27.  
  28.  
  29. output: Python - name of my file ballotpedia__government.py
  30.  
  31. the output
  32.  
  33. File "/home/martin/dev/python/ballotpedia__government.py", line 21
  34. soup.select("table.wikitable.sortable.jquery-
  35. ^
  36. SyntaxError: EOL while scanning string literal
  37. [Finished in 2.337s]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement