编程语言
首页 > 编程语言> > python-Scrapy没有输入解析方法

python-Scrapy没有输入解析方法

作者:互联网

我不明白为什么这段代码没有输入parse方法.
它与文档中的基本蜘蛛示例非常相似:http://doc.scrapy.org/en/latest/topics/spiders.html
而且我很确定这可以在当天早些时候起作用…不确定是否修改了某些内容..

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from scrapy.spider import Spider
from scrapy.selector import HtmlXPathSelector
from scrapy import log
from scrapy.selector import Selector


class jobSpider(Spider):
    name='jobSpider'
    wd = webdriver.Chrome()
    wd.get("some url")
    wd.switch_to_frame("cible")


def parse(self, response):
    log.start()

    wait = WebDriverWait(wd, 10).until(
    (EC.visibility_of_element_located((By.ID, 'blocResultat'))))
    print(wd.page_source)

    stuff=Selector(text=wd.page_source).xpath('//a[contains(@onclick,"win=window.o    pen(\'JobOffs")]').extract() 
    print(stuff)

解决方法:

您的parse(self,response):方法不属于jobSpider类.如果查看Scrapy documentation,您会发现parse方法必须是您的Spider类的方法.

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from scrapy.spider import Spider
from scrapy.selector import HtmlXPathSelector
from scrapy import log
from scrapy.selector import Selector


class jobSpider(Spider):
    name='jobSpider'
    wd = webdriver.Chrome()
    wd.get("https://www.leforem.be/particuliers/offres-emploi-recherche-par-criteres.html?exParfullText=&exPar_search_=true&exParGeographyEdi=true")
    wd.switch_to_frame("cible")


    def parse(self, response):
        log.start()

        wait = WebDriverWait(wd, 10).until(
        (EC.visibility_of_element_located((By.ID, 'blocResultat'))))
        print(wd.page_source)

        stuff=Selector(text=wd.page_source).xpath('//a[contains(@onclick,"win=window.o    pen(\'JobOffs")]').extract() 
        print(stuff)

另外,您需要使用self在parse方法中引用类数据.类中任何数据的前缀.

此外,您在蜘蛛程序上缺少start_urls列表.没有它,蜘蛛将不知道从哪里开始,什么也做不了.

标签:selenium,web-scraping,scrapy,python,web-crawler
来源: https://codeday.me/bug/20191120/2041705.html