简体   繁体   中英

Invalid Syntax Error when running Python script on PythonAnywhere

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")

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM