"I have a Python web scraping code that uses requests and BeautifulSoup to collect data…
- User
"I have a Python web scraping code that uses requests and BeautifulSoup to collect data from multiple pages. However, the code is running into an error, and I'm not sure where the bug is. Could you help me identify which part might be causing the issue without providing the direct solution? I want to understand what could potentially go wrong in the code to learn how to troubleshoot it myself." for page in range(1000, 0, -1): data = [] r = requests.get(f"{url}{page}") content = r.content soup = BeautifulSoup(content, 'html.parser') selector = '.p-30-20' get_freelancer_job = soup.select(selector)
for i in get_freelancer_job: title_selector = '.d-inline' get_title = i.select_one(title_selector).text get_price = int(i.select_one("span.ml-1").text.replace("تومان", "").replace(",", "")) get_location = i.select('.d-sm-block')[1].text.strip() get_descript = i.select_one('.lh-2-31').text get_tag = i.select('.py-1') tags = [] for j in get_tag: tags.append(j.text.strip()) tags = ', '.join(tags) data.append({ 'title': get_title, 'price': get_price, 'location': get_location, 'description': get_descript, 'tags': tags, }) sleep(0.3) - Assistant