简体   繁体   English

使用selenium使用javascript元素进行刮擦尝试

[英]Scraping attempt with javascript elements using selenium

i am a newbie to scraping and selenium. 我是刮硒和硒的新手。 The page which i want to scrape uses a js script on a button to get to the next page. 我想要抓取的页面使用按钮上的js脚本进入下一页。 I found part of a code ( Click a Button in Scrapy ) on SO but i cant seem to make it work. 我在SO上找到了代码的一部分( 在Scrapy中单击一个按钮 ),但我似乎无法使它工作。

from selenium import webdriver

import scrapy

class chSpider(scrapy.Spider):
    name = 'spidypy'
    allowed_domains = ['117.145.177.252']
    start_urls = ['http://117.145.177.252/login.do?method=enterPdamccx']

    def __init__(self):
        self.driver = webdriver.Firefox()

    def parse(self,response):

        self.driver.get('http://117.145.177.252/login.do?method=enterPdamccx')

        while True:
            try:
                next = self.driver.find_element_by_xpath('/html/body/form/div[3]/div/div/a')
                url = 'http://117.145.177.252/login.do?method=enterPdamccx'
                yield Request(url,callback=self.parse2)
                next.click()
            except:
                break

        self.driver.close()

    def parse2(self,response):
        print('you are here!')

I recieve following error messages several times: 我多次收到以下错误消息:

selenium.common.exceptions.WebDriverException: Message: connection refused

那个有一个onclick,所以你会这样做:

driver.execute_script('doMccx()')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM