【发布时间】:2014-11-18 21:21:11
【问题描述】:
我正在尝试抓取一个简单的网站http://hosted.where2getit.com/sharpsiica/index.html?form=locator_search&sku=ARM355&addressline=53203&zip=53203
我已尝试使用以下代码来抓取姓名和地址:
import lxml.html as lh
from selenium import webdriver
import time
browser = webdriver.Firefox()
browser.get('http://hosted.where2getit.com/sharpsiica/index.html?form=locator_search&sku=ARM355&addressline=53203&zip=53203')
time.sleep(5)
content = browser.page_source
tree = lh.fromstring(content)
name=tree.xpath('//table[@id="collection_poi"]/tbody/tr/td[@align="left"]/a/text()')
address=tree.xpath('//table[@id="collection_poi"]/tbody/tr/td[@align="left"]/text()')
print(name,address)
我得到了正确的名字,但是对于地址,我得到了太多不需要的数据。我只需要姓名和地址。
我哪里做错了?
【问题讨论】:
-
如果
selenium本身基本上可以在页面上找到您想要的任何内容,为什么还需要lxml?
标签: python selenium web web-scraping lxml