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?