mardi 3 janvier 2017

How can I activate a list item with selenium and phantomjs?

 from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import NoSuchElementException
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
     "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
     "(KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36")
driver = webdriver.PhantomJS(desired_capabilities = dcap,service_args=['--ignore-ssl-errors=true', '--load-images=false'])
driver.get("http://ift.tt/2hNCgAU")
driver.implicitly_wait(5)
try:
    driver.find_elements_by_xpath("""/html/body/form/div[3]/div[5]/div/div/div/div[4]/div/div/div[5]/div/ul/li[1]""").context_click()
    driver.implicitly_wait(10)
    div_s = driver.find_elements_by_xpath("/html/body/form/div[3]/div[5]/div/div/div/div[4]/div/div/div[5]/div/div[2]/div/div/div/div[1]/div/div/div/h3")
    # div_s = driver.find_elements_by_xpath("""//*[@id="mountRoot"]/div/div/div/div[3]/div/div[2]/div[1]/table/tbody/tr""")
    size_data = ''
    for s in div_s:
        print (str(s.get_attribute("textContent")))
except NoSuchElementException:
    print ("NoSuchElementException")
Traceback (most recent call last):

  File "<ipython-input-6-ec79bd8d183a>", line 12, in <module>
    driver.find_elements_by_xpath("""/html/body/form/div[3]/div[5]/div/div/div/div[4]/div/div/div[5]/div/ul/li[1]""").context_click()

AttributeError: 'list' object has no attribute 'context_click'

I am trying to get the ajax data from a list item. I don't know any other way to activate the li so the data can be scrapped?




Aucun commentaire:

Enregistrer un commentaire