执行错误:未定义变量显示。 (-2753)

时间:2015-05-07 13:16:57

标签: python macos web-scraping beautifulsoup

我正在使用美丽的汤从网站中提取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通知。

OSX通知参考:https://apple.stackexchange.com/questions/57412/how-can-i-trigger-a-notification-center-notification-from-an-applescript-or-shel

1 个答案:

答案 0 :(得分:2)

您需要在命令行中引用AppleScript:

rest_command = """'display notification "{}" with title "{}"'""".format(meaning[0],word[0])
os.system("osascript -e "+ rest_command)