Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import pandas as pd
- list = ['https://ballotpedia.org/Alabama_Supreme_Court',
- 'https://ballotpedia.org/Alaska_Supreme_Court',
- 'https://ballotpedia.org/Arizona_Supreme_Court',
- 'https://ballotpedia.org/Arkansas_Supreme_Court',
- 'https://ballotpedia.org/California_Supreme_Court',
- 'https://ballotpedia.org/Colorado_Supreme_Court',
- 'https://ballotpedia.org/Connecticut_Supreme_Court',
- 'https://ballotpedia.org/Delaware_Supreme_Court']
- temp_dict = {}
- for page in list:
- r = requests.get(page)
- soup = BeautifulSoup(r.content, 'html.parser')
- temp_dict[page.split('/')[-1]] = [item.text for item in
- soup.select("table.wikitable.sortable.jquery-
- tablesorter a")]
- df = pd.DataFrame.from_dict(temp_dict,
- orient='index').transpose()
- df.to_csv('State Supreme Court Justices.csv')
- output: Python - name of my file ballotpedia__government.py
- the output
- File "/home/martin/dev/python/ballotpedia__government.py", line 21
- soup.select("table.wikitable.sortable.jquery-
- ^
- SyntaxError: EOL while scanning string literal
- [Finished in 2.337s]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement