【发布时间】:2014-07-12 22:46:25
【问题描述】:
我正在使用 Selenium-Python 来抓取此链接上的内容。 http://targetstudy.com/school/62292/universal-academy/
HTML代码是这样的,
<tr>
<td>
<i class="fa fa-mobile">
::before
</i>
</td>
<td>8349992220, 8349992221</td>
</tr>
我不知道如何使用 class="fa fa-mobile" 获取手机号码 有人可以帮忙吗。谢谢
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.action_chains import ActionChains
import lxml.html
from selenium.common.exceptions import NoSuchElementException
path_to_chromedriver = 'chromedriver.exe'
browser = webdriver.Chrome(executable_path = path_to_chromedriver)
browser.get('http://targetstudy.com/school/62292/universal-academy/')
stuff = browser.page_source.encode('ascii', 'ignore')
tree = lxml.html.fromstring(stuff)
address1 = tree.xpath('//td/i[@class="fa fa-mobile"]/parent/following-sibling/following-sibling::text()')
print address1
【问题讨论】:
标签: python selenium lxml lxml.html