python - 返回response.meta[]时出错

标签 python scrapy

我正在运行下面的代码,该代码似乎有一些问题。 下面显示的不是我的全部代码,如果有人问我,我将发布其余的代码:

from threading import Thread 
from selenium import webdriver
from scrapy.http import Request
from urlparse import urlparse
from scrapy.spider import BaseSpider

class MySpider(BaseSpider):
    name = "scrapy"
    def get_url():
        url = raw_input('Enter the url of your website (including the http)')
        return url      
    start_url = str(get_url())
    def parse(self,response):
         return response



def get_depth():
    scrapies = MySpider()
    response= Request(scrapies.start_url)
    return response.meta['depth']

错误发生在返回response.meta['深度']处。错误消息没有具体内容,只是说关键错误:深度,所以我不知道如何解决这个问题。这是否意味着深度对于来说不是合适的参数?

谢谢..

最佳答案

您需要使用 Yield 调用 get_depth 并随之传递元值。请参阅下面的示例。

产量请求(url=someurl,callback=self.get_depth,meta={'key': value},)

关于python - 返回response.meta[]时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20337284/

相关文章:

python - 比较两个数据帧并获得差异

python - 如何修复 'Specifier python_version does not match 2.7 (3.6).'

python - 如何在 Python 中实现类似于 Javascript 回调的功能

python - 为 scrapy CrawlSpider 的方法创建单元测试

python - scrapy 如何制作我自己的调度程序中间件

python - 使用 Scrapy 从网站查找和下载 pdf 文件

python - 如何用 pandas DataFrame 中的共享列值替换某些行?

python - 使用 Runge-Kutta 求解耦合微分方程

python - Scrapy:使用 CloudFlare 抓取网站时出现 503 错误

python - 通过扭曲的 inlineCallbacks 运行 Scrapy 蜘蛛