Web scraping works locally but fails on server - empty results returned

Need help with web scraping issue

I built a Discord bot that scrapes trading card prices using BeautifulSoup. Everything works perfectly when I test it on my local computer, but when I deploy it to my hosting server, the scraping returns no data at all.

What I’ve tried:

  • Switched to different target websites
  • Verified encoding is UTF-8 on both environments
  • Double checked my parsing logic

Code example:

response = requests.get(target_url)
soup = BeautifulSoup(response.text, 'html.parser')
price_elements = [element.get_text() for element in soup.findAll('div', class_="card-cost")]
final_prices = []

for element in price_elements:
    price_pattern = re.compile(r'\\-?\\d+\\.\\d+')
    extracted_values = list(map(float, re.findall(price_pattern, element)))
    final_prices.append(str(extracted_values))

print(price_elements)  # Empty on server
print(final_prices)    # Empty on server

Error I get:

IndexError: list index out of range

This happens because my arrays are empty on the server but populated locally. Anyone know why this might be happening? Is it a server configuration issue or something with my code?

your server’s prob missing dependencies or running a diff python version. check if beautifulsoup4 and requests match between ur local setup and server. add some debugging too - print response.status_code and len(response.text) to see what ur actually getting back.

Classic anti-bot blocking. The website’s detecting your automated requests and either blocking them or serving different content. I hit this same issue scraping product data for a price tracker. The site’s probably checking your User-Agent header and seeing it’s from Python requests instead of a real browser. Try mimicking a browser: headers = {‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36’} response = requests.get(target_url, headers=headers) Also, your server IP might be blacklisted. Home IPs usually work fine, but datacenter IPs get flagged all the time.