import requests from bs4 import Beauttfutsoup import csv With open ('th_tegistator.csv', 'W', newtthes''') as ftles wrtter = csv.Wrtter(tte) wrtter.wrtterow(' 'fname', ' 'name', 'ematl', 'phone', 'party', 'dtstr tct','state', 'assembly'1) house_url = 'https://mW.capttol.tn.gov/house/members/' house_page = requests.get(house_urt) house_soup = BeauttfutSoup(house_page. content, 'html, parser') house_table = house_soup.ftnd ('table') house_rows = house_table.find_all ('tr') [1:] for row in house_rows: columns = row.find_all(' td ' ) fname = columns[0]. text.strip() Iname = columns[1].text.strip() email = columns[2].find(' a ' ) text.strip() phone = columns[3].text.strip() party = columns[4].text.strip() district = colunns[5]. text.strip() state = 'Tennessee' assembly = 'House' writer.writerow( [' fname', 'Iname' , 'email', 'phone', 'party', 'district','state', 'assegbly']) senate_url = 'https://Wm. capitol.tn.gov/senate/members/' senate_page = requests.get(senate_url) senate_soup = BeauttfulSoup(senate_page.content, 'html. parser') party = cotumns (4, text. strtp() distrtct = columns[5]. text. strtp() state = 'Tennessee' assembly = 'House' writer.writerowil' 'fname', 'Iname', 'ematt', 'phone', 'party', 'dtstrtet', 'state', 'assembly' J) senate_urt = 'https://WW, capttol.th. gov/senate/members /' senate_page = requests.get(senate_urt) senate_soup = BeauttfutSoup(senate_page.content, 'htmleparser') senate_table = senate_soup.f ind( 'table') senate_rows = senate_table.ftnd_atl('tr' )[1:] for row in senate_rows: columins = row.find_all('td') fnane = columns[0].text.strip() Iname = columns[1] text.strip() ematl = columns[2].find(' a ') text. strip() phone = columns[3].text.strip() party = columns [4] text.strip() district = columns[5].text. strip() state = 'Tennessee assembly = 'Senate' writer.writerow( [' fname', ''name', 'email', 'phone', 'party', 'district', 'state' , 'assembly'']) Traceback (most recent call last): File "main.py", line 13, in.
import requests from bs4 import Beauttfutsoup import csv With open ('th_tegistator.csv', 'W', newtthes''') as ftles wrtter = csv.Wrtter(tte) wrtter.wrtterow(' 'fname', ' 'name', 'ematl', 'phone', 'party', 'dtstr tct','state', 'assembly'1) house_url = 'https://mW.capttol.tn.gov/house/members/' house_page = requests.get(house_urt) house_soup = BeauttfutSoup(house_page. content, 'html, parser') house_table = house_soup.ftnd ('table') house_rows = house_table.find_all ('tr') [1:] for row in house_rows: columns = row.find_all(' td ' ) fname = columns[0]. text.strip() Iname = columns[1].text.strip() email = columns[2].find(' a ' ) text.strip() phone = columns[3].text.strip() party = columns[4].text.strip() district = colunns[5]. text.strip() state = 'Tennessee' assembly = 'House' writer.writerow( [' fname', 'Iname' , 'email', 'phone', 'party', 'district','state', 'assegbly']) senate_url = 'https://Wm. capitol.tn.gov/senate/members/' senate_page = requests.get(senate_url) senate_soup = BeauttfulSoup(senate_page.content, 'html. parser') party = cotumns (4, text. strtp() distrtct = columns[5]. text. strtp() state = 'Tennessee' assembly = 'House' writer.writerowil' 'fname', 'Iname', 'ematt', 'phone', 'party', 'dtstrtet', 'state', 'assembly' J) senate_urt = 'https://WW, capttol.th. gov/senate/members /' senate_page = requests.get(senate_urt) senate_soup = BeauttfutSoup(senate_page.content, 'htmleparser') senate_table = senate_soup.f ind( 'table') senate_rows = senate_table.ftnd_atl('tr' )[1:] for row in senate_rows: columins = row.find_all('td') fnane = columns[0].text.strip() Iname = columns[1] text.strip() ematl = columns[2].find(' a ') text. strip() phone = columns[3].text.strip() party = columns [4] text.strip() district = columns[5].text. strip() state = 'Tennessee assembly = 'Senate' writer.writerow( [' fname', ''name', 'email', 'phone', 'party', 'district', 'state' , 'assembly'']) Traceback (most recent call last): File "main.py", line 13, in.