I have a dictionary that contains company name and the related Better Business Bureau link that accompanies that company. I also have a CSV file that has the BBB link attached to the phone number(s) for those companies. I need to somehow combine the two based on the BBB link that is associated with the company name.
My ultimate end goal is to have a dataframe that contains:
Company Name, Link, Phone Number(s)
DICTIONARY:
{'A. G. Builders, Inc.': 'https://www.bbb.org/us/nc/durham/profile/home-builders/ag-builders-inc-0593-6037923', 'A. R. Russell': 'https://www.bbb.org/us/nc/raleigh/profile/general-contractor/russell-l-judy-builder-inc-0593-90082691', 'A. R. Russell Builders, Inc.': 'https://www.bbb.org/us/nc/raleigh/profile/general-contractor/russell-l-judy-builder-inc-0593-90082691', 'A.C.A. Enterprises, LLC': 'https://www.bbb.org/us/fl/ponce-de-leon/profile/building-contractors/aca-enterprises-llc-0683-90029401', 'A.D. Myers Builders, LLC': 'https://www.bbb.org/us/nc/charlotte/profile/general-contractor/meyer-builders-llc-0473-219405', 'ABS Construction Group': 'https://www.bbb.org/us/nc/newport/profile/general-contractor/ab-building-remodeling-llc-0593-90293532', 'Absolute Construction Group, LLC': 'https://www.bbb.org/us/nc/durham/profile/home-improvement/absolute-construction-group-llc-0593-90282628'}
CODE:
phone_list = []
url_with_phone = []
def phone_numbers():
driver = webdriver.Chrome()
for url in url_list: #Looping through the list of the BBB links
print(url) #Print the URL currently on
driver.get(url)
sleep(randint(4,6))
phone = driver.find_elements_by_class_name("dtm-phone") #FINDS Phone num
sleep(randint(4,8))
print('looking for number')
for p in phone:
results = (p.text)
print(results)
sleep(randint(3,5))
phone_list.append(results) # add phone number to phone_list
sleep(randint(5,9))
url_with_phone.append(url) #adds URL when phone num is found to match up with phone num
phone_numbers()
CSV OUTPUT OF LINKS & PHONE NUMBERS:
URL Searched,Phone Numbers
https://www.bbb.org/us/nc/durham/profile/home-builders/ag-builders-inc-0593-6037923,(919) 384-7005
https://www.bbb.org/us/nc/raleigh/profile/general-contractor/russell-l-judy-builder-inc-0593-90082691,(919) 625-7841
https://www.bbb.org/us/nc/raleigh/profile/general-contractor/russell-l-judy-builder-inc-0593-90082691,(919) 625-7841
https://www.bbb.org/us/fl/ponce-de-leon/profile/building-contractors/aca-enterprises-llc-0683-90029401,(850) 248-0597
https://www.bbb.org/us/fl/ponce-de-leon/profile/building-contractors/aca-enterprises-llc-0683-90029401,(850) 527-1767
https://www.bbb.org/us/nc/charlotte/profile/general-contractor/meyer-builders-llc-0473-219405,(704) 737-8409
For example, the first result in the CSV file belongs to AG Home Builders, is there a way I can add the key from the dictionary (Company Name) to the CSV based on matching the value?
I would want to add the company name to the CSV. What would be the best way to do this? I have read the following links to try and come up with my own results, but haven't had any luck trying the solutions on my own. (append multiple values for one key in a dictionary, list to dictionary conversion with multiple values per key?)