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