简体   繁体   English

通过美丽的汤 4 python 抓取时,错误 nonetype 对象没有属性文本

[英]Error nonetype object has no attribute text while scraping via beautiful soup 4 python

I am trying to extract some info using beautiful soup in python using python webscraping.我正在尝试使用 python webscraping 在 python 中使用漂亮的汤提取一些信息。 Here is the section.这是部分。

<div class="result-value" data-reactid=".0.0.3.0.0.3.$0.1.1">
<span data-reactid=".0.0.3.0.0.3.$0.1.1.0">751</span>
<span class="result-value-unit" data-reactid=".0.0.3.0.0.3.$0.1.1.1">KB</span>
</div


Snap: https://www.dropbox.com/s/d349tb3f22o0wyf/4.png?dl=0

Code I am using is this我正在使用的代码是这个

Sizeofweb=""
try:
    Sizeofweb= soup.find('span', {'data-reactid': ".0.0.3.0.0.3.$0.1.1.0"}).text
    print Sizeofweb
except StandardError as e:
    converted_date="Error was {0}".format(e)
    print converted_date

Error错误

nonetype object has no attribute text

I have tried this but didnt work.我试过这个,但没有用。 Where am I wrong?我哪里错了?

This code works for me -这段代码对我有用 -

from bs4 import BeautifulSoup

html_str = """
<div class="result-value" data-reactid=".0.0.3.0.0.3.$0.1.1">
<span data-reactid=".0.0.3.0.0.3.$0.1.1.0">751</span>
<span class="result-value-unit" data-reactid=".0.0.3.0.0.3.$0.1.1.1">KB</span>
</div>
"""

soup = BeautifulSoup(html_str,"lxml")

Sizeofweb = soup.find('span', {'data-reactid': ".0.0.3.0.0.3.$0.1.1.0"}).text

print Sizeofweb

Output输出

751

One thing I noticed is the last div tag close is missing the close angle bracket - ">"我注意到的一件事是最后一个 div 标签 close 缺少右尖括号 - ">"

Dunno how you've done it but this works for me...不知道你是怎么做到的,但这对我有用......

暂无
暂无

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

相关问题 使用漂亮的汤在 python 中进行网络抓取:AttributeError: 'NoneType' object 没有属性 'text' - web-scraping in python using beautiful soup: AttributeError: 'NoneType' object has no attribute 'text' 美丽的汤有错误:&#39;NoneType&#39; 对象没有属性 &#39;text&#39; - beautiful soup with error : 'NoneType' object has no attribute 'text' 美丽的Soup4&#39;NoneType&#39;对象没有属性&#39;text&#39;错误 - Beautiful Soup4 'NoneType' object has no attribute 'text' Error AttributeError: 'NoneType' object 没有属性'find_all' Python Web 刮花 - AttributeError: 'NoneType' object has no attribute 'find_all' Python Web Scraping w/ Beautiful Soup 用 Beautiful Soup 解析跨度:'NoneType' object 没有属性 'text' - Parse span with Beautiful Soup : 'NoneType' object has no attribute 'text' 美丽的汤:AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;text&#39; - Beautiful soup: AttributeError: 'NoneType' object has no attribute 'text' Beautiful Soup 错误:“NoneType”对象没有属性“find_all” - Beautiful Soup error: 'NoneType' object has no attribute 'find_all' Beautiful Soup 错误“NoneType”对象没有检索股票数据的“text”属性 - Beautiful Soup Error 'NoneType' object has no attribute 'text' retrieving stock data nonetype object 抓取数据时没有属性文本错误 - nonetype object has no attribute text error while scraping data Python 美丽的汤检索给出错误响应'NoneType object 没有属性 getText - Python Beautiful soup retrieval gives an error response 'NoneType object has no attribute getText
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM