我试图解析的网站结构如下所示:
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr height="25">
<td class="th" style="border:none" width="2%"> </td>
<td class="th">movie</td>
<td class="th"> </td>
<td class="th"> </td>
</tr>
<tr id="place_1">
<td style="color: #555; vertical-align: top; padding: 6px">
<a name="1"></a>1.
</td>
<td style="height: 27px; vertical-align: middle; padding: 6px 30px 6px 0">
<a class="all" href="/326/">MOVIE TITLE IN SPANISH</a>
<br/>
<span class="text-grey">MOVIE TITLE IN ENGLISH</span>
</td>
<td style="width: 85px">
<div style="width: 85px; position: relative">
<a class="continue" href="/326/votes/">
9.191
</a>
<span style="color: #777">
(592 184)
</span>
</div>
</td>
</tr>
...
...
...
问题是我无法在span标记中获取文本。我试过.text至于a-tag,也试过.get\text()。但这些都不管用。我的Python代码:
for row in table.find_all('tr')[1:]:
info = row.find_all('td')
movies.append({
'spn_title' : info[1].a.text,
'eng_title' : info[1].span.text,
})
我得到的错误:
AttributeError: 'NoneType' object has no attribute 'get_text'
或者
'eng_title' : info[1].span.text AttributeError: 'NoneType' object has no attribute 'text'
请尝试以下操作。另外,检查soup变量,因为我可以毫无问题地运行代码。我怀疑在HTML后面的某个地方,你没有一个这样的出现在一行中。你知道吗
如果类名是一致的,则只能筛选具有相应类型元素的限定行类。使用bs4.7.1。你知道吗
否则,您需要一种方法来处理不存在的情况。例如
我认为你应该用innerHTML。你知道吗
应该有用。你知道吗
相关问题 更多 >
编程相关推荐