Scrapy 不进入解析方法

Scrapy not entering parse method

我不明白为什么这段代码没有进入解析方法。 它与文档中的基本蜘蛛示例非常相似: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 class。如果您查看 Scrapy documentation,您会发现 parse 方法需要是您的蜘蛛 class.

的方法
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)

此外,您需要通过在 class.[=17= 中的任何数据上使用 self. 前缀来引用 parse 方法中的 class 数据]

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

您必须使用 self 访问属性,并且 parse 是 class 的一部分。

def parse(self, response):
    log.start()
    wait = WebDriverWait(self.wd, 10).until(
    (EC.visibility_of_element_located((By.ID, 'blocResultat'))))
    print(self.wd.page_source)
    stuff=Selector(text=self.wd.page_source).xpath('//a[contains(@onclick,"win=window.o    pen(\'JobOffs")]').extract() 
    print(stuff)