【问题标题】:Element only available after inspect element in selenium元素仅在检查硒元素后可用
【发布时间】:2016-12-27 08:26:46
【问题描述】:

我正在尝试从here 获取联系人姓名,但我遇到了一个非常奇怪的问题。内容在浏览器中可见,但是当我使用 selenium 使用 xpath 查找元素时,我没有得到任何数据。只要我点击检查元素,selenium 就会找到数据。

mydriver = webdriver.Chrome()
print 'Webdriver Started'
mydriver.get('http://listings.fta-companies-au.com/l/101662595/BNP-Paribas-in-Sydney-NSW')
contact_persons = mydriver.find_elements_by_xpath('//div[@class="data-block is-editable no-header"]//div[@class="srp-float-wrap flt-scroll-wrap"]//table[@class="srp-widget-table"]/tbody/tr')
for p in contact_persons:
    print p.text

当我只是加载并尝试查找数据时,它会返回一个空列表,但只要我点击检查元素,我就会得到所需的数据。

我也尝试过使用 requests 和 lxml 进行解析,但它们也返回空数据。

【问题讨论】:

    标签: python-2.7 selenium xpath web-scraping


    【解决方案1】:

    似乎只有在您滚动到详细信息表时才会设置它。尝试使用 driver.moveto.... 函数移动到带有文本的 h2 标签——员工和高管。这应该可以提供详细信息。

    【讨论】:

    • 创造了奇迹。如果有人想知道,我使用了这个代码 title = mydriver.find_element_by_xpath('//h2[contains(text(),"Employees")]') hover = ActionChains(mydriver).move_to_element(title) hover.perform()
    猜你喜欢
    • 2018-11-09
    • 2015-01-12
    • 2017-07-05
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多