2016-08-20 40 views
0

我想從here獲取聯繫人姓名,我正面臨一個非常奇怪的問題。內容在瀏覽器中可見,但是當我使用硒查找使用xpath的元素時,我沒有收到任何數據。只要點擊檢測元素,硒就會找到數據。元素僅在硒中的檢查元素後可用

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 

當我只是加載,並嘗試找到數據,它會返回一個空列表,但只要我點擊檢查元素,我會得到所需要的數據。

我也嘗試過使用請求和lxml來解析,但他們也返回空數據。

回答

0

似乎只有當您滾動到它時,纔會設置詳細信息表。嘗試使用文本 - 員工和主管,使用driver.moveto ....功能移動到h2標籤。這應該使細節可用。

+0

工作奇蹟。如果有人想知道,我用這個代碼 title = mydriver.find_element_by_xpath('// h2 [contains(text(),「Employees」)]') hover = ActionChains(mydriver).move_to_element(title) hover。執行() –