【问题标题】:How to share the cookies that CrawlSpider holded to the webview request(pywebkit)?如何将 CrawlSpider 持有的 cookie 共享给 webview 请求(pywebkit)?
【发布时间】:2013-12-20 13:09:20
【问题描述】:

我正在通过 Scrapy 抓取一些页面(在同一域下)。

有一些特殊的页面是由JS生成的,所以我使用ScrapyJS并将页面加载到webview中,这样JS就可以执行了。但是 webview 中加载的网页是对网站的新请求。 webview 中的响应会将页面重定向到站点登录页面,这不是我想要的。

在我看来,我已经在 MyTestSpider 中登录了该站点。如果 webview 的请求可以持有/共享/读取来自 MyTestSpider 的 cookie,它将使 JS 生成的页面表现良好,就像通过正确的用户登录一样,而不是重定向到站点登录页面。

我所拥有的: 类 MyTestSpider(CrawlSpider):

    def start_requests(self):
        self.prelogin()

    def prelogin(self):
        //login prepares

    def login(self):
        //login the website and hold the cookie

    def parse_item(self, response):
        //parse the items

有没有人对此问题有更好的解决方案? 任何帮助都会得到帮助......:p

【问题讨论】:

    标签: javascript python cookies scrapy


    【解决方案1】:

    看到这个scrapy feature

    要启动一个启用了持久性支持的蜘蛛,请像这样运行它:

    scrapy crawl somespider -s JOBDIR=crawls/somespider-1
    

    然后,您可以随时安全地停止蜘蛛(通过按 Ctrl-C 或发送信号),稍后通过发出相同的命令来恢复它:

    scrapy crawl somespider -s JOBDIR=crawls/somespider-1
    

    【讨论】:

    • 谢谢,但我真的不明白如何使用 scrapy-jobs 功能解决我的问题。你能解释一下它的细节吗?
    猜你喜欢
    • 1970-01-01
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 2013-01-06
    • 2021-01-28
    相关资源
    最近更新 更多