简体   繁体   English

如何使用 scrapy 从 html 标签中提取数据

[英]How to extract data from html tag with scrapy

I need to extract address information from this HTML code.我需要从这个 HTML 代码中提取地址信息。

     <span>
        <span class="icon"> <i class="fas fa-building"></i> </span> 8  Phạm Hùng
         Cau Giay
         Ha Noi
     </span>

How can I get that information.我怎样才能得到这些信息。 If I do something like如果我做类似的事情

response.css('div.company-info__location').get()

I got back我回来了

<div class="company-info__location">      <span>\n        <span class="icon"> <i class="fas fa-building"></i> </span> 8  Phạm Hùng\nCau Giay\nHa Noi\n 
     </span>\n    </div>

Or或者

response.css('div.company-info__location::text').get()

It only return space.它只返回空间。 Not exactly what I want不完全是我想要的

You can try string() XPath expression:你可以试试string() XPath 表达式:

response.xpath('string(//div[@class="info__location"])').get()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM