2017-07-16 71 views
0

我可以得到其他td的内线所有的文本元素文本中,除tdclass="datapid"的Python - 硒无法获得与PhantomJS

<tr> 
    <td class="cregion">JP</td> 
    <td class="datacompany"><a href="/company/10644-tecmo">Tecmo</a></td> 
    <td class="datapid">P99-00001</td> 
    <td class="datapid">4960677070033</td> 
    <td class="cdate">02/06/03</td> 
    <td class="datarating">&nbsp;</td> 
    </tr> 

我使用硒与PhantomJS 2.1.1:

driver = webdriver.PhantomJS(
"c:/phantomjs-2.1.1-windows/bin/phantomjs.exe") 

试图让字段,但只有datapid字段为空:

cregions = driver.find_elements(
    By.CLASS_NAME, "cregion") 
    for region in cregions: 
     regions.append(region.text) 

    datacompanies = driver.find_elements(
    By.CLASS_NAME, "datacompany") 
    for company in datacompanies: 
     publishers.append(company.find_element(By.XPATH, "a").text) 

    datapids = driver.find_elements(
    By.CLASS_NAME, "datapid") 
    for i in range(0, (len(datapids))): 
     if i % 2: 
      pids.append(datapids[i].text) //datapids[i].text = '' 
+0

读取数据空间中的pid: pids.append(pid.text) –

回答

0

最大化窗口后:

driver.maximize_window() 

现在我能得到div内的文本。

我认为这是因为webdriver不是简单地阅读源代码,而是从Windows中获取它。如果node在窗口之外,则无法通过webdriver