# Inputs Current File Here is the file I'm looking at. It might be truncated from…
- User
User: # Inputs
Current File
Here is the file I'm looking at. It might be truncated from above and below and, if so, is centered around my cursor.
import requests from bs4 import BeautifulSoup import json # def scrape_company_urls(url): # response = requests.get(url) # if response.status_code != 200: # print(f"Failed to retrieve page. Status code: {response.status_code}") # return None # soup = BeautifulSoup(response.content, 'html.parser') # container = soup.find('div', class_='search_cardsContainer__jTGn4') # if container: # links = container.find_all('a', href=True) # # Extract company names, filter out '/de', and remove duplicates # company_names = list(set( # link['href'].split('/')[-1] for link in links if link['href'] != '/de' # )) # return json.dumps(company_names) # return None def scrape_company_strengths(url_company): response = requests.get(url_company) if response.status_code != 200: print(f"Failed to retrieve page. Status code: {response.status_code}") return None soup = BeautifulSoup(response.content, 'html.parser') strength_section = soup.find('section', class_='index__topFactorList__J8yDG') if strength_section: strengths = {} for item in strength_section.find_all('li', class_='index__container__yePeh'): header = item.find('h3', class_='p-small-bold') percentage = item.find('h3', class_='h5') if header and percentage: strengths[header.text.strip()] = percentage.text.strip() return strengths return None url = 'https://www.kununu.com/de/search?country=de&location=city-2fbd1016-893c-4ef0-bea2-7e709129d312' url_company = f"https://www.kununu.com/de/deutsche-post/kultur" # company_urls_json = scrape_company_urls(url) company_strengths = scrape_company_strengths(url_company) print(company_strengths) # print(company_urls_json)User:
Write another function that scrapes the url_company and fetches the key and value pairs that are in the table under the element "index__topFactorList__J8yDG"
The section looks like this -
To create a new function that scrapes the
url_companyand fetches the key-value pairs from the specified section, we will use BeautifulSoup to parse and retrieve the desired data.Here is the updated code with the new function:
# ... existing imports ... def scrape_company_strengths(url_company): response = requests.get(url_company) if response.status_code != 200: print(f"Failed to retrieve page. Status code: {response.status_code}") return None soup = BeautifulSoup(response.content, 'html.parser') # Find the section with the specified class strength_section = soup.find('section', class_='index__topFactorList__J8yDG') if strength_section: strengths = {} # Assuming each item holds a key-value structure in the given format for item in strength_section.find_all('li', class_='index__container__yePeh'): header = item.find('h3', class_='p-small-bold') percentage = item.find('h3', class_='h5') if header and percentage: # Store the header text as key and percentage text as value strengths[header.text.strip()] = percentage.text.strip() return strengths return None # ... existing code ... company_strengths = scrape_company_strengths(url_company) print(company_strengths) - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.