Ich bekomme den Fehler AttributeError: 'NoneType' -Objekt hat kein Attribut 'findAll' jedes Mal, wenn ich das untenstehende Python-Skript ausführen. Ich habe einige Nachforschungen angestellt und ein paar Posts gefunden, die angeben, dass ich vielleicht "None" übergebe, wenn ich versuche, die Bilder zu finden, weshalb es Fehler gibt. Ich habe immer noch keine Lösung. Jede Information ist hilfreich. HierPython-Fehler beim Versuch, Image-Links abzurufen
ist der vollständige Fehler:
Traceback (most recent call last):
File "D:\Program Files\Parser Python\Test.py", line 33, in <module>
for img in divImage.findAll('img'):
AttributeError: 'NoneType' object has no attribute 'findAll'
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.common.exceptions import TimeoutException
import os
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'
os.environ["PATH"] += "C:\Python27\Lib\site-packages\selenium-2.53.6-py2.7.egg\selenium"
#binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(capabilities=firefox_capabilities)
# it takes forever to load the page, therefore we are setting a threshold
driver.set_page_load_timeout(5)
try:
driver.get("http://readcomiconline.to/Comic/Flashpoint/Issue-1?id=19295&readType=1")
except TimeoutException:
# never ignore exceptions silently in real world code
pass
soup2 = BeautifulSoup(driver.page_source, 'html.parser')
divImage = soup2.find('div', {"id": "divImage"})
#divImage = soup2.find('div', {"id": "containerRoot"})
# close the browser
driver.close()
for img in divImage.findAll('img'):
print img.get('src')
Hilft Ihnen dieses Thema? Link: http://stackoverflow.com/questions/18065768/python-attributeerror-nonetype-object-has-no-attribute-findall – Tenzin
Dies könnte auch relevant sein http://stackoverflow.com/questions/31419641/python-scraper -unable-to-scrape-img-src. BTW warum das Java-Tag? – doctorlove
Omg das war ein Unfall. Ich habe ursprünglich versucht, dies mit JSOUP in Java zu erreichen, also glaube ich, dass ich Java im Kopf habe. Entschuldigen Sie. –