【发布时间】:2013-12-06 08:06:10
【问题描述】:
我需要从这个页面上抓取电话号码,例如 - http://m.avito.ru/sankt-peterburg/muzykalnye_instrumenty/shesti_strunnoe_bandzho_stroy_gitarnyy_203671253
左蓝色按钮执行此 ajax 请求并返回电话号码,而不是在 innerText 中,而是在像这样的单独 text() 节点中
<a href="tel:895**49****" class="button-text action-link" title="Телефон продавца" rel="nofollow">
"8 9** **9-99-**"
</a>
我点击这个按钮。等待 3-5 秒,然后尝试获取号码 但我不能像这样使用 .text
phone = driver.find_element_by_class_name('button-text')
print phone.text
它只返回一个空字符串 当我尝试这样做时
print driver.find_element_by_xpath('/html/body/section/article/section[2]/ul/li[1]/a/text()')
或者这个
print driver.find_element_by_xpath('/html/body/section/article/section[2]/ul/li[1]/a/text()').text
它返回 InvalidSelectorException: Message: u'Error Message => \'xpath 表达式的结果 "/html/body/section/article/section[2]/ul/li[1]/a/ text()" 是:[对象文本]。它应该是一个元素。
【问题讨论】:
标签: python dom text selenium selenium-webdriver