Selenium PhantomJS webdriver不支持cli

2024-09-21 01:20:18 发布

您现在位置:Python中文网/ 问答频道 /正文

这段代码在使用firefoxwebdriver时运行得非常好。但对于PhantomJS,它不会单击所需的javascript链接。你知道吗

driver = webdriver.PhantomJS()
driver.get("http://justbet.co.ke/index.php?option=com_justbet&league=1539&Itemid=123")
options = driver.find_elements_by_xpath("//td[@class='optionmore']")
for more in range(0, len(options)):
        options[more].click()
        sleep(3)

Tags: 代码httpgetindex链接moredriverjavascript
1条回答
网友
1楼 · 发布于 2024-09-21 01:20:18

如果选择optionmore类中的a标记,则代码可以工作:

from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("http://justbet.co.ke/index.php?option=com_justbet&league=1539&Itemid=123")
options = driver.find_elements_by_xpath("//td[@class='optionmore']/a")
print(driver.find_elements_by_xpath("//td[@class='suboption ']"))
for opt in options:
    opt.click()
print(driver.find_elements_by_xpath("//td[@class='suboption ']"))

运行上面的代码:

In [27]: from selenium import webdriver

In [28]: driver = webdriver.PhantomJS()    
In [29]: driver.get("http://justbet.co.ke/index.php?option=com_justbet&league=1539&Itemid=123")    
In [30]: options = driver.find_elements_by_xpath("//td[@class='optionmore']/a")    
In [31]: print(len(driver.find_elements_by_xpath("//td[@class='suboption ']")))
0

In [32]: for opt in options:
   ....:         opt.click()
   ....:     

In [33]: print(len(driver.find_elements_by_xpath("//td[@class='suboption ']")))
270

你得到了所有你想要的td数据。你知道吗

相关问题 更多 >

    热门问题