Python 文本文件中的刮擦开始URL
我试图在url中爬行并检索每个url的h1。url存储在文本文件中。代码是:Python 文本文件中的刮擦开始URL,python,scrapy,web-crawler,Python,Scrapy,Web Crawler,我试图在url中爬行并检索每个url的h1。url存储在文本文件中。代码是: class MySpider(CrawlSpider): name = "sitemaplocation" allowed_domains = ["xyz.nl"] f = open("locationlist.txt",'r') start_urls = [url.strip() for url in f.readlines()] f.close() def parse(s
class MySpider(CrawlSpider):
name = "sitemaplocation"
allowed_domains = ["xyz.nl"]
f = open("locationlist.txt",'r')
start_urls = [url.strip() for url in f.readlines()]
f.close()
def parse(self, response):
sel = Selector(response)
title= sel.xpath("//h1[@class='no-bd']/text()").extract()
print title
代码在站点中爬行,但不打印任何内容。任何帮助都会很有用。尝试放置以下内容:
name = "sitemaplocation"
allowed_domains = ["xyz.nl"]
f = open("locationlist.txt",'r')
start_urls = [url.strip() for url in f.readlines()]
f.close()
进入
方法
还有,您在哪里调用解析函数?尝试从以下继承您的spider: 在编写爬网爬行器规则时,避免使用解析作为回调,因为 爬行爬行器使用解析方法本身来实现其逻辑。 因此,如果重写解析方法,爬网爬行器将不再 工作
文件中的所有URL是否都来自
中指定的同一域\u domains
?您应该分析日志,查看是否筛选了任何请求。
__init__