【发布时间】:2015-04-10 21:05:48
【问题描述】:
我认为可能有一个简单的解决方案来解决这个问题......我要做的就是提取文本,列出带有我的变量项目 ['genre'] 的流派类型,足够简单......但是,作为我正在提取的项目仅出现在我从一次抓取的页面上,当循环浏览其他项目(例如项目 ['艺术家'] 时,项目 ['流派'] 不包括在内。任何帮助,将不胜感激。这是我认为相关的代码。
def parse_item(self, response):#http://stackoverflow.com/questions/15836062/scrapy-crawlspider-doesnt-crawl-the-first-landing-page
for info in response.xpath('//div[@class="entry vevent"] | //div[@id="page"]'):
item = TutorialItem() # Extract items from the items folder.
item ['artist'] = info.xpath('.//span[@class="summary"]//text()').extract() # Extract artist information.
item ['date'] = info.xpath('.//span[@class="dates"]//text()').extract() # Extract date information.
preview = ''.join(str(s)for s in item['artist'])
item ['genre'] = info.xpath('.//div[@class="header"]//text()').extract()
真的希望这是有道理的,如果没有,请道歉!
【问题讨论】:
-
发布相关的 HTML 或链接到您尝试抓取的页面..
-
allgigs.co.uk/whats_on/London/clubbing-1.html 你会看到我试图提取的单词clubbing overview。每页一次,而不是与其他项目并排
-
我猜你不是在询问 XPath 来获取那个词,不是吗?那么再次提取那个词有什么问题呢?
-
对不起,我不明白...我的问题是,当返回结果时,我得到了艺术家姓名,事件的日期。但是,项目类型返回空。它只在爬虫访问下一页时显示一次。这不好,因为我需要将信息添加到数据库中
-
也许您应该简单地将
item ['genre'] = info.xpath('.//div[@class="header"]//text()').extract()语句放在循环之外