它不从标题中收集数据。我在样本中做了,但仍然不起作用。这是我的代码:
托斯特.py:
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors import LinkExtractor
from toster.items import DjangoItem
class DjangoSpider(CrawlSpider):
name = "django"
allowed_domains = ["www.toster.ru"]
start_urls = [
'http://www.toster.ru/tag/django/questions',
]
rules = [
Rule(LinkExtractor(
allow=['/tag/django/questions\?page=\d']),
callback='parse_item',
follow=True)
]
def parse_item(self, response):
selector_list = response.css('div.thing')
for selector in selector_list:
item = DjangoItem()
item['title'] = selector.xpath('div/h2/a/text()').extract()
yield item
有什么帮助吗
代码中存在多个问题:
allowed_domains
中删除www.
\d
替换为\d+
unique=False
让Scrapy处理分页页parse_item()
中的提取逻辑—例如,这些页面上没有带有thing
类的元素固定版本(适用于我):
相关问题 更多 >
编程相关推荐