简体   繁体   English

Beautiful Soup AttributeError: 'NoneType' object has no attribute 'find_all' 即使网页结构相同

[英]Beautiful Soup AttributeError: 'NoneType' object has no attribute 'find_all' even though webpage is structured the same

so I have working code for one web-scraper and want to use it on another website which is structured the same.所以我有一个网络爬虫的工作代码,并想在另一个结构相同的网站上使用它。

The code I have that works is:我拥有的代码是:

url = "https://efl.network/index/efl/LeaguePassingStats.html"
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
tb = soup.find('table', class_='tablesorter')
table_rows = tb.find_all("tr")

however if i change the url to但是,如果我将url更改为

https://sim-football.com/indexes/DSFLS22/LeaguePassingStats.html

it gives me the error它给了我错误

table_rows = tb.find_all("tr")
AttributeError: 'NoneType' object has no attribute 'find_all'

Both websites seem to be structured the same however.然而,这两个网站的结构似乎相同。

This line returns None此行返回无

tb = soup.find('table', class_='tablesorter')

That means, there is no table element with class 'tablesorter' on the page.这意味着,页面上没有带有 class 'tablesorter' 的表格元素。

If you print out page.content you can see this is the HTML that is returned: '<head><title>Not Acceptable.</title></head><body><h1>Not Acceptable.</h1><p>An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.</p></body></html>'如果您打印出page.content ,您可以看到这是返回的 HTML: '<head><title>Not Acceptable.</title></head><body><h1>Not Acceptable.</h1><p>An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.</p></body></html>' '<head><title>Not Acceptable.</title></head><body><h1>Not Acceptable.</h1><p>An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.</p></body></html>'

So the website is blocking your web scrape for some reason and returning this error HTML, in which the table element you're looking for doesn't exist, causing your error因此,该网站出于某种原因阻止了您的 web 抓取并返回此错误 HTML,其中您要查找的table元素不存在,导致您的错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'NoneType' object 没有属性'find_all' Python Web 刮花 - AttributeError: 'NoneType' object has no attribute 'find_all' Python Web Scraping w/ Beautiful Soup Beautiful Soup 错误:“NoneType”对象没有属性“find_all” - Beautiful Soup error: 'NoneType' object has no attribute 'find_all' AttributeError:“函数”对象没有属性“ find_all”美丽汤 - AttributeError: 'function' object has no attribute 'find_all' Beautiful Soup NoneType object has no attribute find_all error using beautiful Soup - NoneType object has no attribute find_all error using beautiful Soup Python 错误:'NoneType' object 没有使用 Beautiful Soup 的属性 'find_all' - Python Error: 'NoneType' object has no attribute 'find_all' using Beautiful Soup Beautiful Soup 中 span 标签上的 find_all 产生 AttributeError:ResultSet 对象没有属性“get_text” - find_all on span tag in Beautiful Soup yields AttributeError: ResultSet object has no attribute 'get_text' 美丽的汤:“ ResultSet”对象没有属性“ find_all”吗? - Beautiful Soup: 'ResultSet' object has no attribute 'find_all'? Python - Beautiful Soup 4 - &#39;NavigableString&#39; 对象没有属性 &#39;find_all&#39; - Python - Beautiful Soup 4 - 'NavigableString' object has no attribute 'find_all' AttributeError:&#39;NoneType&#39;对象没有属性&#39;find_all&#39;Beautifulsoup - AttributeError: 'NoneType' object has no attribute 'find_all' Beautifulsoup AttributeError: 'NoneType' object 没有属性 'find_all' (BeautifulSoup) (ChromeDriver) - AttributeError: 'NoneType' object has no attribute 'find_all' (BeautifulSoup) (ChromeDriver)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM