我正在尝试使用pythonwebscraping在python中使用beautifuldsoup提取一些信息。这是一节
<div class="result-value" data-reactid=".0.0.3.0.0.3.$0.1.1">
<span data-reactid=".0.0.3.0.0.3.$0.1.1.0">1.1</span>
<span class="result-value-unit" data-reactid=".0.0.3.0.0.3.$0.1.1.1">MB</span>
</div>
我想得到1.1的值
我使用的部分代码是
try:
Area =soup.select(".result-value span")
print Area
except StandardError as e:
converted_date="Error was {0}".format(e)
print converted_date
我得到的结果是
[]
有什么不对劲
假设您知道
data-reactid
的值,您可以得到如下正确的元素:同样,如果
soup.find('span', {'data-reactid': '.0.0.3.0.0.3.$0.1.1.0'}).text
有效,代码不会返回任何错误消息。您得到的结果消息至少显示了try...except...
函数正在工作。我猜问题出在你的htmlfile
上,它必须是bytes
而不是str
。我建议您修改一下代码,如下所示:然后继续剩下的
相关问题 更多 >
编程相关推荐