【发布时间】:2020-09-04 07:09:36
【问题描述】:
我需要从网上抓取下表,我无法使用“find_all”功能解决问题。 PyCharm 总是说:
AttributeError: 'NoneType' object has no attribute 'find_all'
我不知道出了什么问题。尝试使用 table.find_all("tr") 或 table.find_all('tr') 字符和下一个属性,如 table.find_all("tr", attrs={"class": "table table-export"}) 和下一个选项,没有任何效果。 请问你能告诉我我做错了什么吗?
表:
<div class="table-options">
<table class="table table-export">
<thead>
<tr>
<!-- ngIf: ActuallyPoints && ActuallyPoints.name == 'AXB' --><th ng-if="currentRole && currentRole.name == 'AXB'" class="id check">
<label ng-click="selectAll()"><input disabled="" id="select-all" type="checkbox" ng-model="all" class="valid value-ng">All</label>
</th><!-- end ngIf: currentRole && currentRole.name == 'AXB' -->
<th>AAA</th>
<th>BBB</th>
<th>CCC</th>
</tr>
</thead>
<tbody>
<!-- ngRepeat: x in ErrorStatus --><tr ng-repeat="x in ErrorStatus" class="random-id">
<!-- ngIf: currentRole && currentRole.name == 'AXB' --><td ng-if="currentRole && currentRole.name == 'AXB'" class="random-id">
<input type="checkbox" ng-model="x.checked" ng-change="selectOne(x)" class="valid value-ng">
</td><!-- end ngIf: currentRole && currentRole.name == 'AXB' -->
<td class="pax">111</td>
<td class="pax">222</td>
<td class="pax">333</td>
</td>
</tr><!-- end ngRepeat: x in ErrorStatus -->
</tbody>
</table>
</div>
代码:
import lxml
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = 'xxx'
website = request.urlopen(url).read()
soup = BeautifulSoup(website, "lxml")
table = soup.find("table", attrs={"class": "table table-export"})
rows = table.find_all('tr')
非常感谢。
【问题讨论】:
-
您尝试抓取的网址是什么。请在您的代码中添加它
-
很抱歉,这是一个带有机密数据库的私人网址,很遗憾,我无法与所有人共享它,并且需要登录..
-
那么我担心你在这里得不到任何帮助。如果其他人不能实时复制问题,那么它不值得解决。
标签: python selenium web-scraping beautifulsoup attributeerror