Ich versuche, einige Informationen aus einigen HTML mit Python BeautifulSoup zu extrahieren.BeautifulSoup findAll Variablentyp Problem
Sudsection der HTML:
<div class="ui-grid-canvas">
<!-- -->
<div class="ui-grid-row" ng-class="{'ui-grid-tree-header-row': row.treeLevel > -1, 'ui-grid-row-dirty': row.isDirty, 'ui-grid-row-saving': row.isSaving, 'ui-grid-row-error': row.isError,'ui-grid-row-selected': row.isSelected}" ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" ng-style="Viewport.rowStyle(rowRenderIndex)">
<div role="row" row-render-index="rowRenderIndex" ui-grid-row="row">
<div role="row">
<!-- -->
<div class="ui-grid-cell ui-grid-coluiGrid-0005" ng-class="{sorted: col.name==$parent.$parent.$parent.$parent.$parent.$parent.$parent.datatableImpl.sortedColumn}" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" role="gridcell" tabindex="0" ui-grid-cell="">
<div class="ui-grid-cell-contents" ng-bind-html="row.entity[col.field].content" title="Alnwick-Haldimand">Alnwick-Haldimand</div>
</div>
<!-- -->
<div class="ui-grid-cell ui-grid-coluiGrid-0006" ng-class="{sorted: col.name==$parent.$parent.$parent.$parent.$parent.$parent.$parent.datatableImpl.sortedColumn}" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" role="gridcell" tabindex="0" ui-grid-cell="">
<div class="ui-grid-cell-contents" ng-bind-html="row.entity[col.field].content" title="Alderville Community Centre">Alderville Community Centre</div>
</div>
<!-- -->
<div class="ui-grid-cell ui-grid-coluiGrid-0007" ng-class="{sorted: col.name==$parent.$parent.$parent.$parent.$parent.$parent.$parent.datatableImpl.sortedColumn}" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" role="gridcell" tabindex="0" ui-grid-cell="">
<div class="ui-grid-cell-contents" ng-bind-html="row.entity[col.field].content" title="Under construction">Under construction</div>
</div>
<!-- -->
<div class="ui-grid-cell ui-grid-coluiGrid-0008" ng-class="{sorted: col.name==$parent.$parent.$parent.$parent.$parent.$parent.$parent.datatableImpl.sortedColumn}" ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" role="gridcell" tabindex="0" ui-grid-cell="">
<div class="ui-grid-cell-contents" ng-bind-html="row.entity[col.field].content" title="March 2018">March 2018</div>
</div>
<!-- -->
</div>
</div>
<!-- -->
<!-- -->
</div>
Ich bin ein seltsamen Fehler zu stoßen. Das Folgende ist ein Codeblock, für die das Problem auftritt ist:
table = page_soup.findAll('div',attrs={"class" : "ui-grid-canvas"})
print(type(table[0]))
rows = table[0].findAll('div',attrs={"class": "ui-grid-row"})
print(type(rows[0]))
cell = rows[0].findALL('div')
print(type(cells))
Diese Zeilen geben die folgenden:
<class 'bs4.element.Tag'>
<class 'bs4.element.Tag'>
TypeError Traceback (most recent call last)
<ipython-input-56-13fce9e4b865> in <module>()
5 print(type(rows[0]))
6
----> 7 cell = rows[0].findALL('div')
8 print(type(cells))
TypeError: 'NoneType' object is not callable
Warum ist dies eine Art Fehler zurückgegeben, wenn die Überprüfung der Variablentyp direkt über zeigt an, dass es sich um eine bs4.element.Tag handelt, die bei der Tabellenvariablen funktioniert hat?
Verwenden von Ubuntu, Python 3.6 und BS4.
Vielen Dank im Voraus.