0

I'm trying to run the Python script that I wrote for scraping a particular website, and then I need to get notified with an email when the price reaches a specific number, for that matter I used PythonAnywhere, but when I run my script in the console, I get the following error, even though it runs normally on Pycharm:

File "<stdin>", line 1
    python3 main.py
            ^
SyntaxError: invalid syntax

Here's my code:

from bs4 import BeautifulSoup
import requests
import smtplib


response = requests.get("https://order.badinanshipping.com/profile/b763bd64-1064-426a-b949-d8e5232919ee/invoice")
badini_page = response.text


def send_email(email, password, message):
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(email, password)
    server.sendmail(email, email, message)
    server.quit()

soup = BeautifulSoup(badini_page, "html.parser")
price = soup.find(class_="my-box2")
net_price = int(price.getText().split("IQD")[0])


if net_price > 75000:
    send_email("myEmail", "myPassword",
               "\n\n*******\n\n Go pick them up, now! \n\n*******\n\n")
CodeManiac
  • 33
  • 6

2 Answers2

1

Looks like you're running python command inside the python interpreter.

Python 3.7 (default)
[Clang 4.0 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'python3' is not defined
>>> python3 main.py
  File "<stdin>", line 1
    python3 main.py
               ^
SyntaxError: invalid syntax

You can open the terminal and type in your command or try

>>> exec(open("./main.py").read())

How to execute a file within the Python interpreter?

1

You need to run that command in the bash console, not in the python console.

Filip
  • 1,008
  • 6
  • 12
  • I ran it in bash console and I got this error: requests.exceptions.ProxyError: HTTPSConnectionPool(host='order.badinanshipping.com', port=443): Max retries exceeded with url: /profile/b763bd64- 1064-426a-b949-d8e5232919ee/invoice (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden'))) – CodeManiac Jan 07 '22 at 14:15
  • 1
    It looks like you're running in a free PythonAnywhere account and are trying to access a site that is not on the whitelist: https://www.pythonanywhere.com/whitelist/ – Giles Thomas Jan 08 '22 at 15:57