First, I will give you some potentially helpful context about my code. Then, I…
- User
User: First, I will give you some potentially helpful context about my code. Then, I will show you the selection and give you the instruction. The selection will be in
/Users/adityajain/Documents/Scraper/scaper.py.This is my current file. The selection will be denoted by comments "Start of Selection" and "End of Selection":
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 # Start of Selection 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 # End of Selection 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: Please rewrite this selection following these instructions:
Edit Prompt
There is another section right under the one with class "index__topFactorList__J8yDG", which has the same class, but has weaknesses. How do I also get that section? The main div in which these sections are has the class "index__content__HTaY9 index__contentSpacing__+Zgzn".
Selection to Rewrite
# Start of Selection 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 # End of Selection - Assistant
# Start of Selection def scrape_company_factors(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') factors = {'strengths': {}, 'weaknesses': {}} content_div = soup.find('div', class_='index__content__HTaY9 index__contentSpacing__+Zgzn') if not content_div: return None for section in content_div.find_all('section', class_='index__topFactorList__J8yDG'): items = section.find_all('li', class_='index__container__yePeh') category = None # Determine if the section is 'strengths' or 'weaknesses' by checking for known headers. first_item_header = items[0].find('h3', class_='p-small-bold').text.strip() if items else None if first_item_header: if "Strength" in first_item_header: # Adjust this logical condition as per actual content clues category = 'strengths' elif "Weakness" in first_item_header: # Adjust this logical condition as per actual content clues category = 'weaknesses' if category: for item in items: header = item.find('h3', class_='p-small-bold') percentage = item.find('h3', class_='h5') if header and percentage: factors[category][header.text.strip()] = percentage.text.strip() return factors if any(factors.values()) else None # End of Selection
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.