Forums

Error message after python file compilation that I do not get locally on my computer but only on pythonanywhere

Error message that I get after compilation: 13:58 ~/BEST_DEALS_BOT $ python3 BEST_DEALS_2.py SEARCH STARTED...
Traceback (most recent call last):
File "BEST_DEALS_2.py", line 72, in <module>
soup = getdata(url_main)
File "BEST_DEALS_2.py", line 22, in getdata
r.html.render(sleep=1)
File "/home/mortilus/.local/lib/python3.8/site-packages/requests_html.py", line 586, in render
self.browser = self.session.browser # Automatically create a event loop and browser
File "/home/mortilus/.local/lib/python3.8/site-packages/requests_html.py", line 730, in browser
self._browser = self.loop.run_until_complete(super().browser)
File "/usr/lib/python3.8/asyncio/base_events.py", line 608, in run_until_complete
return future.result()
File "/home/mortilus/.local/lib/python3.8/site-packages/requests_html.py", line 714, in browser
self._browser = await pyppeteer.launch(ignoreHTTPSErrors=not(self.verify), headless=True, args=self.__browser_args)
File "/home/mortilus/.local/lib/python3.8/site-packages/pyppeteer/launcher.py", line 306, in launch
return await Launcher(options, **kwargs).launch()
File "/home/mortilus/.local/lib/python3.8/site-packages/pyppeteer/launcher.py", line 167, in launch
self.browserWSEndpoint = get_ws_endpoint(self.url)
File "/home/mortilus/.local/lib/python3.8/site-packages/pyppeteer/launcher.py", line 226, in get_ws_endpoint
raise BrowserError('Browser closed unexpectedly:\n')
pyppeteer.errors.BrowserError: Browser closed unexpectedly:

this is my code: from requests_html import HTMLSession from bs4 import BeautifulSoup import pandas as pd import argparse import telegram import sys import time import requests

searchterm = args.searchterm

searchterm = 'tv'

s = HTMLSession() dealslist = []

url_main = f'https://www.amazon.it/s?k={searchterm}'

def getdata(url): try: r = s.get(url) r.html.render(sleep=1) soup = BeautifulSoup(r.html.html, 'html.parser') except requests.exceptions.RequestException as e: print('EXCEPTION CIAO: ' + e) return #r = s.get(url) #r.html.render(sleep=1) #soup = BeautifulSoup(r.html.html, 'html.parser') return soup

def getdeals(soup): products = soup.find_all('div', {'data-component-type': 's-search-result'}) for item in products: saleprice = 0 title = item.find('a', {'class': 'a-link-normal a-text-normal'}).text.strip() short_title = item.find('a', {'class': 'a-link-normal a-text-normal'}).text.strip()[:25] link = 'https://www.amazon.it' + item.find('a', {'class': 'a-link-normal a-text-normal'})['href'] try: saleprice = float(item.find_all('span', {'class': 'a-offscreen'})[0].text.replace('€','').replace(',','.').strip()) oldprice = float(item.find_all('span', {'class': 'a-offscreen'})[1].text.replace('€','').replace(',','.').strip()) except: oldprice = 0 try: reviews = float(item.find('span', {'class': 'a-size-base'}).text.strip()) except: reviews = 0

    saleitem = {
        'title': title,
        'short_title': short_title,
        'link': link,
        'saleprice': saleprice,
        'oldprice': oldprice,
        'reviews': reviews
        }

    if int(saleitem["reviews"]) > 50 and int(saleitem["oldprice"]) > 0:
        dealslist.append(saleitem)
return

def getnextpage(soup): pages = soup.find('ul', {'class': 'a-pagination'}) if not pages.find('li', {'class': 'a-disabled a-last'}): url_main = 'https://www.amazon.it' + str(pages.find('li', {'class': 'a-last'}).find('a')['href']) return url_main else: return

print('SEARCH STARTED...') while True: soup = getdata(url_main) getdeals(soup) url_main = getnextpage(soup) if not url_main: break print('SEARCH ENDED...')

bot = telegram.Bot(token='secret') for deal in dealslist: htmlMsg = '\U00002B55 <b>' + str(deal['short_title']) + '</b>\n\n'\ '\U0001F525 <b>' + str(deal['saleprice']) + '</b> invece di <s>' + str(deal['oldprice']) + '€</s>\n'\ '\U000027A1 <a href="' + str(deal['link']) + '">AGGIUDICATI L OFFERTA</a>\n'\ '\U00002B50 <b>' + str(deal['reviews']) + '</b> recensioni'

bot.send_photo(chat_id=-secret,photo=deal['link'],parse_mode='HTML',caption=htmlMsg)
time.sleep(5)

print('')

print('STARTED CSV FILE CREATION..')

df = pd.DataFrame(dealslist)

df['percentoff'] = 100 - ((df.saleprice / df.oldprice) * 100)

df = df.sort_values(by=['percentoff'], ascending=False)

df.to_csv(searchterm + '-bfdeals.csv', index=False)

print('ENDED CSV FILE CREATION')

In this small program, I find all deals in amazon and it fails in soup = getdata(url_main). Can anyone help me please?

Thank you in advance

Amazon does not like being scrapped from the well known headless servers.