Reputation: 11
I've created a loop that scrapes website data (Deal ID and destinations) using Chromedriver and adds them to a list. I want to pair the Deal ID with the values taken from the destination table and add them to a dictionary. Each website scrape iteration has a different number of destinations (sometimes up to 20), but only one Deal ID.
I want my dictionary to have an output similar to:
dicts = {'Deal ID #123': ['Lisbon, Portugal', Seville, Spain'], 'Deal ID #456' : ['Monte Carlo, Monaco', 'Marseille, France', 'Istanbul,
Turkey', 'Myrina (Limnos), Greece']}
Here is code so far:
dicts = {}
fast_deal_list = []
table_data = []
for link in urllistsmall:
driver = webdriver.Chrome(r"C:\Users\me\chromedriver.exe")
driver.get(link)
driver.find_element_by_name("LogEmail").send_keys(username)
driver.find_element_by_css_selector("#MemberForm .btn").click()
soup = BeautifulSoup(driver.page_source, "html.parser")
for fast_deal_x in soup.find('h1'):
fast_ids = fast_deal_x.get_text()
fast_deal_list.append(fast_ids)
for table_x in soup.find_all(target="_blank"):
table_data_run = table_x.get_text()
table_data.append(table_data_run)
Upvotes: 1
Views: 77
Reputation:
you can use this code:
dicts['Deal ID #123'] = ['Lisbon, Portugal', Seville, Spain']
dicts['Deal ID #456'] = ['Monte Carlo, Monaco', 'Marseille, France', 'Istanbul, Turkey', 'Myrina (Limnos), Greece']
Upvotes: 2