from urllib.request import urlopen
from bs4 import BeautifulSoup
html= urlopen("http://www.pythonscraping.com/pages/page3.html")
soup= BeautifulSoup(html.read())
print(soup.find("img",{"src":"../img/gifts/img1.jpg"
}).parent.previous_sibling.get_text())
上面的代码工作正常,但不是下面的那个。它给出了如上所述的属性错误。谁能告诉我原因?属性错误:'NoneType'对象没有属性'parent'
from urllib.request import urlopen
from bs4 import BeautifulSoup
html= urlopen("http://www.pythonscraping.com/pages/page3.html")
soup= BeautifulSoup(html.read())
price =soup.find("img",{"src=":"../img/gifts/img1.jpg"
}).parent.previous_sibling.get_text()
print(price)
谢谢! :)
都得到$ 15.00 – Serge
希望我能说的一样。我曾尝试重新启动和一切,但同样的错误。我会尝试看看代码一次。由于 – Xexus