我正在尝试抓取网址并检索每个网址的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(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()
进入
__init__
MySpider 类中的方法。
你在哪里调用解析函数?
关于python - 文本文件中的Scrapy start_urls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22960140/