Reputation: 43
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")
Upvotes: 1
Views: 1450
Reputation: 676
You need to run that command in the bash console, not in the python console.
Upvotes: 0
Reputation: 41
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?
Upvotes: 1