我正在使用 beautiful soup 从网站中提取 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)
该脚本基本上会获取多个单词
及其含义
,将它们存储在数组中,然后将它们显示为 OSX 通知。
最佳答案
您需要在命令行中引用 AppleScript:
rest_command = """'display notification "{}" with title "{}"'""".format(meaning[0],word[0])
os.system("osascript -e "+ rest_command)
关于python - 执行错误 : The variable display is not defined. (-2753),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30102224/