I am trying to write code to loop through ~90k pages on a website in order to scrape data, and I'm trying to get started using a "with" statement. My csv file has one column called "Symbol" and I can share that if needed.
I understand that this is a syntax error, but I don't see what the error is. I've tried changing the last line to something else, but I always get the same error. I read in another thread that "with" closes itself, so I'm not sure what else I should do.
In terms of my eventual plans, I would like to write a loop to iterate through all 90k websites, scraping data. I have code for some of the subsequent steps, so if there is a better way for me to do this step I am all ears about other solutions.
Thank you!
My code:
with open('~/plants_symbols.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
try:
rkey = requests.get('https://plants.usda.gov/java/reference' + row['Symbol'])
if rkey.status_code == 200:
print("hooray!")
File "", line 7 print("hooray!") ^ SyntaxError: unexpected EOF while parsing