【发布时间】:2018-01-27 23:51:56
【问题描述】:
我正在使用 Selenium 和 BeautifulSoup 手动爬取列表中的网页并保存数据。我在尝试使用 find 和 findAll 方法时遇到了一些麻烦。
Here's the exact HTML I'm working with。我把它贴在 Pastebin 上是因为它有很多。
如果我想提取这个 HTML 中的值,比如里面的文本
<div class="item value nowrap">4 Bedrooms 3 Bathrooms</div>
或者
<td class="value" originalvalue="6229">
6,229 sq ft
</td>
我该怎么做?我试过使用以下代码:
soup = BeautifulSoup(''.join(html))
j = soup.find('item value nowrap')[0].text
print j
我收到以下错误:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/crawl/main.py", line 39, in <module>
j = soup.find('item value nowrap')[0].text
TypeError: 'NoneType' object has no attribute '__getitem__'
有人能指出我正确的方向吗?如何使用 BeautifulSoup 获取这些值?
【问题讨论】:
标签: python selenium beautifulsoup