返回时出错响应.meta[ ]

2024-04-20 06:49:00 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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']

错误发生在return response.meta['depth']。错误消息没有特定的内容,它只是说key error: depth,所以我不确定如何修复它。这不意味着这个论点不合适吗?在

谢谢。。在


Tags: 代码fromimporthttpurlgetreturnresponse
1条回答
网友
1楼 · 发布于 2024-04-20 06:49:00

您需要使用Yield来调用get_depth并将meta值与之一起传递。请参阅下面的示例。在

屈服请求(url=someurl,回调=self.get_深度,meta={'key':value},)

相关问题 更多 >