scrapy xpath selector repeats data

后端 未结 1 1560
礼貌的吻别
礼貌的吻别 2020-12-12 01:12

I am trying to extract the business name and address from each listing and export it to a -csv, but I am having problems with the output csv. I think bizs = hxs.select(\"//

相关标签:
1条回答
  • 2020-12-12 01:16

    you should add one "." to select the relative xpath, and here is from scrapy document(http://doc.scrapy.org/en/0.16/topics/selectors.html)

    At first, you may be tempted to use the following approach, which is wrong, as it actually extracts all

    elements from the document, not only those inside elements:

    >>> for p in divs.select('//p') # this is wrong - gets all <p> from the whole document
    >>>     print p.extract()
    

    This is the proper way to do it (note the dot prefixing the .//p XPath):

    >>> for p in divs.select('.//p') # extracts all <p> inside
    >>>     print p.extract()
    
    0 讨论(0)
提交回复
热议问题