I need scrape the following table from the web and I cannot solve the issue with "find_all" function. The PyCharm always says:
AttributeError: 'NoneType' object has no attribute 'find_all'
I dont know what is wrong. Trying it with table.find_all("tr") or table.find_all('tr') characters and with next attributes like table.find_all("tr", attrs={"class": "table table-export"}) and next options and nothing works. Please could you tell me what I doing wrong?
Table:
<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>
Code:
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')
Many thanks.