【发布时间】:2019-09-04 15:29:12
【问题描述】:
我尝试解析的网站结构如下所示:
<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-tag 中获取文本。我试过 .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' 对象没有属性 'get_text'
或
'eng_title' : info[1].span.text AttributeError: 'NoneType' object has 没有属性“文本”
【问题讨论】:
标签: python html parsing web-scraping beautifulsoup