1
我正在构建使用CrawlSpider类的抓取工具。我怀疑链接提取器一遍又一遍地循环相同的链接。有没有办法限制链接提取和拒绝已被刮掉的链接?这可以在拒绝输入中没有正则表达式的情况下完成吗?Scrapy链接提取器否认以前刮过的链接
My Rules look like this:
{
rules = (
#Rule(SgmlLinkExtractor((allow='profile')), follow=True),
Rule(SgmlLinkExtractor(deny='feedback\.html'),callback='parse_item', follow=True),
)
}
And my parse_item is:
{
def parse_item(self, response):
hxs = HtmlXPathSelector(response)
element = hxs.select('//table[@id="profilehead"]/tr/td/a/@href').extract()
try:
open('urls.txt', 'a').write(element[0])
open('urls.txt', 'a').write('\n')
except IndexError:
# Site doesn't have link to another website
pass
}
如果您发布充分蜘蛛的代码和你试图抓取的网站,我们可以看看是否正在分析相同的链接。 – Talvalin