【发布时间】:2015-09-03 04:01:59
【问题描述】:
我不明白为什么这段代码没有进入解析方法。 它与文档中的基本蜘蛛示例非常相似: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 作为参数,它应该是类的一部分吗?
-
doc.scrapy.org/en/latest/topics/spiders.html 参见示例。无需调用它。他们也把自己作为论据
-
要么您的代码不正确,要么您的缩进错误。请修复缩进,使其与脚本中的缩进相同。
-
已修复。在我的代码中是正确的
标签: python selenium web-scraping web-crawler scrapy