无处不在,我仍然不知道它为什么会给出错误。这是一个YouTube教程,我的代码是相同的,所以我不知道为什么它会在下面提到的行中引发这个'NavigableString'错误(我在Python 2.7和3.5中都试过)。BeautifulSoup +请求>> AttributeError:'NavigableString'对象没有属性'find_all'
import requests
from bs4 import BeautifulSoup
url= "https://example.com"
r = requests.get(url)
soup = BeautifulSoup(r.content)
data = soup.find_all("div", {"class": "example"})
for item in data:
print item.contents[0].find_all("a", {"class": "ex"}) # Error line
编辑:其他有用的信息
教程:在教程http://youtube.com/watch?v=3xQTJi2tqgk
示例代码(时间:29:16):https://youtu.be/3xQTJi2tqgk?t=29m16s
网址教程:http://www.yellowpages.com/los-angeles-ca/coffe?g=los%20angles%2c%20ca&q=coffe
'NavigableString'指内标签的纯文本从而可以没有subelementes,所以它不需要'find_all'。 – furas
更好的问题添加链接到教程和网址,我们看到如果你的代码是真正相同的(如果它可以与当前页面 - 也许在页面上更改的东西)。 – furas
https://www.youtube.com/watch?v=3xQTJi2tqgk – Keretto