【发布时间】:2012-05-16 20:21:51
【问题描述】:
当我运行以下命令时,我收到“AttributeError: 'NoneType' object has no attribute 'string'”。但是,当对块字符串变量执行相同的任务时;有用。
关于我做错了什么的任何想法?
from BeautifulSoup import BeautifulSoup
from urllib import urlopen
url = ("https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=Albert%20Einstein&explaintext")
print ((BeautifulSoup(((urlopen(url)).read()))).find('extract').string).split("\n", 1)[0]
【问题讨论】:
-
这么多括号...我的眼睛受伤了。你真的需要阅读PEP8
标签: python beautifulsoup