Untitled conversation
- User
import requests from bs4 import BeautifulSoup import json from lxml import html # 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 # url = 'https://www.kununu.com/de/search?country=de&location=city-2fbd1016-893c-4ef0-bea2-7e709129d312' # company_urls_json = scrape_company_urls(url) # print(company_urls_json) # .............................................. def scrape_company_info(url): response = requests.get(url) if response.status_code != 200: print(f"Failed to retrieve page. Status code: {response.status_code}") return None tree = html.fromstring(response.content) # Extract Mitarbeiter:innen-Zufriedenheit employee_satisfaction = tree.xpath('//div[@class="index__block__7hodp"]/span[@class="h5 index__score__BktQY"]/text()') employee_satisfaction = employee_satisfaction[0].strip() if employee_satisfaction else None # Extract additional scores categories = tree.xpath('//div[@class="index__scoreBreakdownContainer__vG9I-"]//li[@class="index__item__F4hKn"]') scores = {} for category in categories: category_name = category.xpath('.//span[@class="index__itemName__GpEyp p-small-semibold"]/text()') category_score = category.xpath('.//span[@class="h5 index__score__BktQY"]/text()') if category_name and category_score: scores[category_name[0].strip()] = category_score[0].strip() factors = category.xpath('.//ul[@class="index__factorList__ZDKkP"]/li') for factor in factors: factor_name = factor.xpath('.//span[@class="index__factorName__ilaK1 p-tiny-regular text-dark-63"]/text()') factor_score = factor.xpath('.//span[@class="index__factorScore__sV-a1 h6"]/text()') if factor_name and factor_score: scores[factor_name[0].strip()] = factor_score[0].strip() return { 'employee_satisfaction': employee_satisfaction, 'scores': scores } url = 'https://www.kununu.com/de/berlin-brands-group' company_info = scrape_company_info(url) print(company_info)Write a scraper code that visits the link https://www.kununu.com/de/berlin-brands-group and fetches everything that is inside the following component:
- Assistant
To scrape everything inside the specified component
<ul class="index__list__7ApgR">, you can update the function in your given code. This involves modifying the XPath to target the desired elements within that and extracting the information contained there. Here's how to update your code to achieve that:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.