点击与Python

问题描述:

我试图使用python脚本与硒这个网站(https://www.tusubtitulo.com/season/26/10)下载的文件中的硒链接点击与Python

这是代码:

from selenium import webdriver 

site="https://www.tusubtitulo.com/season/26/10" 
driver = webdriver.PhantomJS() 
el = driver.find_element_by_link_text("Descargar").click() 
driver.close() 

但我M个接收这个错误:

raise exception_class(message, screen, stacktrace) 

NoSuchElementException: {"errorMessage":"Unable to find element with link text 'Descargar'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"97","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:53425","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"link text\", \"value\": \"Descargar\", \"sessionId\": \"be219f20-26b5-11e7-bfb9-63e6de8a8a0a\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/be219f20-26b5-11e7-bfb9-63e6de8a8a0a/element"}} 

链接查看的XPath:http://imgur.com/a/kNWzC 我也有使用XPath试过了,在几个答案解释,机智h结果相同:

from selenium import webdriver 

site="https://www.tusubtitulo.com/season/26/10" 
driver = webdriver.PhantomJS() 
xpath=".//*[@id='episodes']/table[1]/tbody/tr[3]/td[7]/a" 
el = driver.find_element_by_xpath(xpath).click() 
driver.close() 

具有相同的结果。

但是,如果我使用了 “WebDriverWait” 的方式,我得到一个不同的错误:

from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 

site="https://www.tusubtitulo.com/season/382/7" 
driver = webdriver.PhantomJS() 
xpath = ".//*[@id='episodes']/table[3]/tbody/tr[3]/td[7]/a" 
element = WebDriverWait(driver, 10).until(
     EC.presence_of_element_located((By.XPATH, xpath))).click() 
driver.close() 

错误:

raise TimeoutException(message, screen, stacktrace) 

TimeoutException 

任何帮助将不胜感激。

我是您所指向的网站的管理员。我们的系统不允许脚本请求。您需要从浏览器下载。这是我们的规则。

+0

不是我期待的答案!我可以问你为什么是你的规则? –

+0

这不是一个有效的答案 –