简体   繁体   English

在抓取“aria-label”内容时获取“NoneType object 不可下标”

[英]Getting “NoneType object is not subscriptable” while scraping the 'aria-label' content

I am scraping a website using BeautifulSoup4 that has the content under it's aria-label tag.我正在使用 BeautifulSoup4 抓取一个网站,该网站的内容位于aria-label标签下。 I have condensed down my hierarchy to a single tag but when I am trying to extract the data from it, it gives me this error: "TypeError: 'method' object is not subscriptable"我已经将我的层次结构压缩为一个标签,但是当我试图从中提取数据时,它给了我这个错误: "TypeError: 'method' object is not subscriptable"

A variable right_elem gives me the list of all the tags I am interested in:变量 right_elem 为我提供了我感兴趣的所有标签的列表:

right_elem = change_script[41].findAll("circle")

and the following is one of the tags I am interested:以下是我感兴趣的标签之一:

<circle aria-label="Filling capacity of the engine is 24 liters" class="graph-bullet" cx="0" cy="0" fill="#ffffff" fill-opacity="1" r="4" stroke="#ffffff" stroke-opacity="0" stroke-width="2" transform="translate(4,177)"></circle>

I have tried the following so far to overcome this issue but found no success:到目前为止,我已经尝试了以下方法来克服这个问题,但没有成功:

- right_elem[0].select_one('[class*="graph-bullet"][aria-label]')['aria-label']
- right_elem[0].find("circle", class_="graph-bullet")["aria-label"]

Any help would be appreciated.任何帮助,将不胜感激。

Try: right_elem[0].find("circle", attrs={'class': 'graph-bullet'}).attrs["aria-label"]试试: right_elem[0].find("circle", attrs={'class': 'graph-bullet'}).attrs["aria-label"]

Cause when you use right_elem[0].find("circle", class_="graph-bullet") you just get HTML Parsing (Soup Object).因为当您使用right_elem[0].find("circle", class_="graph-bullet")时,您只会得到 HTML Parsing (Soup Object)。 And when you call .attrs it will return a dictionary of all attributes.当您调用.attrs时,它将返回所有属性的字典。 Then you subscript it by ["aria-label"] .然后用["aria-label"]它下标。 Hope it will work.希望它会奏效。

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

相关问题 获取 TypeError:'NoneType' object 在 Web 抓取中不可下标 - Getting TypeError: 'NoneType' object is not subscriptable in Web Scraping 使用 beautifulsoup 抓取 aria-label 的数据 - Data scraping of an aria-label with beautifulsoup Web 抓取'NoneType' object 不可下标 - Web Scraping 'NoneType' object is not subscriptable 从Twitter收集坐标字段时,无法获取“ NoneType”对象 - Getting 'NoneType' object is not subscriptable while collecting coordinates field from Twitter TypeError:“ NoneType”对象不可下标python web抓取 - TypeError: 'NoneType' object is not subscriptable python web scraping Web 刮<span class="“b6a29bc0”" aria-label="“Baths”">python</span> <span class="“b6a29bc0”" aria-label="“Beds”">2、2</span> - Web scraping python <span class=“b6a29bc0” aria-label=“Beds”>2</span>, <span class=“b6a29bc0” aria-label=“Baths”>2</span> 出现“ TypeError: 'NoneType' object is not subscriptable” 错误 - Getting “ TypeError: 'NoneType' object is not subscriptable” error TypeError:'NoneType' object 在进行拆分时不可下标 - TypeError: 'NoneType' object is not subscriptable while doing split 我不断收到“ NoneType对象不可下标” - I keep getting “NoneType object is not subscriptable” 切片数组时出现“ TypeError:&#39;NoneType&#39;对象无法下标” - “TypeError: 'NoneType' object is not subscriptable” while slicing array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM