【发布时间】:2016-07-19 09:28:51
【问题描述】:
我是使用xpath的新手,
我想从this link中提取每个标题、正文、链接、发布日期
一切似乎都还好,但身体上没有,如何提取嵌套 xPath 上的每一个身体,谢谢 :)
这里是我的来源
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from thehack.items import ThehackItem
class MySpider(BaseSpider):
name = "thehack"
allowed_domains = ["thehackernews.com"]
start_urls = ["http://thehackernews.com/search/label/mobile%20hacking"]
def parse(self, response):
hxs = HtmlXPathSelector(response)
titles = hxs.xpath('//article[@class="post item module"]')
items = []
for titles in titles:
item = ThehackItem()
item['title'] = titles.select('span/h2/a/text()').extract()
item['link'] = titles.select('span/h2/a/@href').extract()
item['body'] = titles.select('span/div/div/div/div/a/div/text()').extract()
item['date'] = titles.select('span/div/span/text()').extract()
items.append(item)
return items
【问题讨论】:
-
'body'需要解决什么问题?你得到什么?你在期待什么? -
我想得到这篇文章的主要内容,讨论什么文章……但是我什么都得不到,伙计
-
你能帮我保罗吗?
标签: python xpath scrapy web-crawler