【问题标题】:Scraping title from alibaba using scrapy使用scrapy从阿里巴巴抓取标题
【发布时间】:2018-08-18 23:48:16
【问题描述】:

我想从这个链接中删除此页面的标题,即义乌市珠宝商有限公司:https://www.alibaba.com/energy-jewelrys-suppliers.html

html代码sn-p是:

 <a target="_blank" title href="//cnmj.en.alibaba.com/company_profile.html#top-nav-bar" data-hislog="230670293" data-domdot="id:2638,sid:230670293">Yiwu City MJ <strong>Jewelry</strong> Co., Ltd.</a>

我有这个代码:

response.xpath('//*[@class="title ellipsis"]/a/text()').extract()

但输出是:

['Yiwu City Mj ',
 ' Jewelery',
'Co. Ltd.']

问题是它应该是列表中的单个项目而不是多个项目。我怎么做?谢谢

【问题讨论】:

    标签: python xpath web-scraping scrapy


    【解决方案1】:

    由于a 中的子strong 标记,您会得到这个。

    要解决此问题,您可以尝试。

    "".join(response.xpath('//*[@class="title ellipsis"]/a//text()').extract())
    

    希望这有助于解决问题。

    【讨论】: