我不知道如何使用语句driver.find_element(By.LINK_TEXT,

时间:2013-08-20 04:31:34

标签: python selenium web-scraping screen-scraping splinter

我试着写

driver.find_element(By.LINK_TEXT, value='10').click()

我得到以下命令行反馈:

    uname = driver.find_element(By.LINK_TEXT, '10').click()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 680, in find_element
    {'using': by, 'value': value})['value']
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 165, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 164, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: u'no such element\n
 (Session info: chrome=28.0.1500.95)\n  (Driver info: chromedriver=2.2,platform=
Windows NT 6.1 SP1 x86_64)'

我的陈述的其他排列产生了一些类似的反馈。 (我写的'10'是指向另一页的链接,例如“1 2 3 4 5 6 7 8 9 10 ......”)

我正在尝试转到第10页。我不知道如何。即使到第2行也是一个开始,我会很满意。

感谢您的帮助。

更新

如果我写driver.find_element_by_link_text('10').click(),我会得到这样的反馈:

    uname = driver.find_element_by_link_text('10').click()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 246, in find_element_by_link_text
    return self.find_element(by=By.LINK_TEXT, value=link_text)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 680, in find_element
    {'using': by, 'value': value})['value']
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 165, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 164, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: u'no such element\n
 (Session info: chrome=28.0.1500.95)\n  (Driver info: chromedriver=2.2,platform=
Windows NT 6.1 SP1 x86_64)'

更新II:这是我必须处理的代码:

import time
import win32ui
import win32api
import win32con
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from ctypes import *
from selenium.webdriver.common.by import By


driver = webdriver.Chrome()
driver.get('http://[site]');

1 个答案:

答案 0 :(得分:0)

试试这个:

driver.find_element_by_link_text('10').click()