我正在使用美丽的汤从网站中提取2组数据。奇怪的是,我收到以下错误!
错误;
0:7: execution error: The variable display is not defined. (-2753)
代码:
import requests
import os
from bs4 import BeautifulSoup
word = []
meaning = []
r = requests.get("XYZ.com")
content = BeautifulSoup(r.content)
for words in content.findAll('span', attrs={'class':'qWord'}):
word.append(unicode.join(u'\n',map(unicode,words.text)))
for word_meanings in content.findAll('span', attrs={'class':'qDef'}):
meaning.append(unicode.join(u'\n',map(unicode,word_meanings.text)))
rest_command = 'display notification \"%s\" with title \"%s\"'.format(meaning[0],word[0])
os.system("osascript -e "+ rest_command)
该脚本基本上取多个words
及其meanings
,将它们存储在数组&然后将它们显示为OSX通知。
答案 0 :(得分:2)
您需要在命令行中引用AppleScript:
rest_command = """'display notification "{}" with title "{}"'""".format(meaning[0],word[0])
os.system("osascript -e "+ rest_command)