我将HTML代码放在这里:
<div class="rendering rendering_person rendering_short rendering_person_short">
<h3 class="title">
<a rel="Person" href="https://moh-it.pure.elsevier.com/en/persons/massimo-eraldo-abate" class="link person"><span>Massimo Eraldo Abate</span></a>
</h3>
<ul class="relations email">
<li class="email"><a href="massimo.abate@ior.it" class="link"><span>massimo.abate@ior.it</span></a></li>
</ul>
<p class="type"><span class="family">Person: </span>Academic</p>
</div>
从上面的代码中如何提取Massimo Eraldo Abate?
请帮帮我。
发布于 2017-08-29 06:58:36
您可以使用以下命令提取名称
response.xpath('//h3[@class="title"]/a/span/text()').extract_first()
另外,请看这个Scrapinghub的blogpost以了解XPath的介绍。
发布于 2017-08-29 06:59:50
请看一下这一页。提取文本scrapy docs的方法有很多种
>>> body = '<html><body><span>good</span></body></html>'
>>> Selector(text=body).xpath('//span/text()').extract()
>>> response = HtmlResponse(url='http://example.com', body=body)
>>> Selector(response=response).xpath('//span/text()').extract()
https://stackoverflow.com/questions/45932513
复制相似问题