[英]Invalid Syntax Error when running Python script on PythonAnywhere
我正在尝试运行我为抓取特定网站而编写的 Python 脚本,然后当价格达到特定数字时,我需要收到 email 的通知,为此我使用了 PythonAnywhere,但是当我在控制台,我收到以下错误,即使它在 Pycharm 上正常运行:
File "<stdin>", line 1
python3 main.py
^
SyntaxError: invalid syntax
这是我的代码:
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")
看起来您正在 python 解释器中运行 python 命令。
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
您可以打开终端并输入您的命令或尝试
>>> exec(open("./main.py").read())
您需要在 bash 控制台中运行该命令,而不是在 python 控制台中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.