我正在使用Python运行BeautifulSoup和Twilio,以此作为识别我所在地区免费食物的一种方式。
我正在使用下面的代码,这些代码是我用notepad++编写的,然后在我的downloads文件夹中保存为experiment.py。
from bs4 import BeautifulSoup
import requests
from twilio.rest import TwilioRestClient
import re
url = 'https://postmates.com/new-york-city'
account_sid = 'XXX'
auth_token = 'XXX'
twilio_phone_number = '+15551254565'
my_phone_number = '+15551234567'
webpage = requests.get(url)
soup = BeautifulSoup(webpage.text, 'html.parser')
free_regex = re.compile('free')
all_strings = list(soup.stripped_strings)
free_food = [s for s in all_strings if free_regex.match(s.lower())]
if free_food:
body = 'Free Postmates!\n\n' + '\n'.join(free_food)
client = TwilioRestClient(account_sid, auth_token)
client.messages.create(
body=body,
to=my_phone_number,
from=twilio_phone_number
)当我尝试在终端中通过输入cd downloads experiment.py来运行这个命令时,我得到了以下消息。
文件"experiment.py",第25行from=twilio_phone_number ^ SyntaxError:无效语法
是什么导致了这种情况的发生。我在这里看不到语法错误。
发布于 2017-03-13 13:22:27
from=twilio_phone_numberfrom是python中的一个关键字,将其更改为from_或其他什么。
https://stackoverflow.com/questions/42757079
复制相似问题