this script needs to run all the way through RI_page_urls.csv, then run through all the resulting urls from RI_License_urls.csv and grab the business info.
it's pulling all the url's from RI_page_urls.csv, but then only running and printing the first of 100 urls from RI_License_urls.csv. Need help figuring out how to make it wait for the first part to complete before running the second part.
I appreciate any and all help.
Here's a url for the RI_page_urls.csv to start with:
http://www.crb.state.ri.us/verify_CRB.php
and the code:
from bs4 import BeautifulSoup as soup
import requests as r
import pandas as pd
import re
import csv
#pulls lic# url
with open('RI_page_urls.csv') as f_input:
csv_input = csv.reader(f_input)
for url in csv_input:
data = r.get(url[0])
page_data = soup(data.text, 'html.parser')
links = [r'www.crb.state.ri.us/' + link['href']
for link in page_data.table.tr.find_all('a') if re.search('licensedetail.php', str(link))]
df = pd.DataFrame(links)
df.to_csv('RI_License_urls.csv', header=False, index=False, mode = 'a')
#Code Above works!
#need to pull table info from license url
#this pulls the first record, but doesn't loop through the requests
with open('RI_License_urls.csv') as f_input_2:
csv_input_2 = csv.reader(f_input_2)
for url in csv_input_2:
data = r.get(url[0])
page_data = soup(data.text, 'html.parser')
company_info = (' '.join(info.get_text(", ", strip=True).split()) for info in page_data.find_all('h9'))
df = pd.DataFrame(info, columns=['company_info'])
df.to_csv('RI_company_info.csv', index=False)