我有一个非常简单的爬虫,但是当我试图搜索我正在抓取的项目的内容时,它没有被找到
被抓取的url:https://www.filmlinc.org/nyff2019/films/the-irishman/
蜘蛛
import scrapy
from metrograph.items import MetrographItem
class MetrographSpider(scrapy.Spider): #**************Change This*****************
name = 'metrograph' #**************Change This*****************
start_urls = ['https://www.filmlinc.org/nyff2019/films/the-irishman/',
]
def parse(self, response):
title=response.xpath('//div[7]//a[1]//span[1]/text()').getall()
)
if "Standby" in item['title']:
print(item['title'])
yield item但是蜘蛛在抓取的字段中找不到“备用”这个词。但是,如果我手动将其获取到print(item['title'])
我得到了以下内容,其中很明显包含了这个词。我删除了一些空格
['\n \n
\n\n Standby Only\n ']我不确定为什么我会有麻烦?标题项是列表吗?有没有办法对它进行正确的搜索?最终,爬行器会在没有找到“备用”的情况下寻找一个场景,但显然我现在还不能这样做,如果这对任何可能的建议有影响的话。
谢谢!
发布于 2019-09-14 05:16:29
您正在尝试在列表中查找一个字符串来查找整个项目,而您只需要一个字符串就可以将列表转换为str
"Standby" in str(['\n \n \n\n Standby Only\n '])https://stackoverflow.com/questions/57930348
复制相似问题