【问题标题】:can't extract data using scrapy无法使用scrapy提取数据
【发布时间】:2019-03-17 15:08:35
【问题描述】:

我正在尝试从以下页面提取地址名称:https://property.spatialest.com/nc/durham/#/property/100016

property_spider.py:

from scrapy import Spider
from scrapy.selector import Selector

from property.items import PropertyItem

class PropertySpider(Spider):
    name = "property"
    allowed_domains = ["property.spatialest.com"]
    start_urls = [ 
        "http://property.spatialest.com/nc/durham/#/property/100016"
    ]   

    def parse(self, response):
        address = Selector(response).xpath("//html/body/main/div/div[2]/div/div[1]/div[2]/div/section/div/div[1]/div[2]/header/div/div/div[1]/div[2]/span")

        address_item = PropertyItem()
        address_item['address'] = address.xpath('span[@class="value "]/text()').extract()
        yield address_item

蜘蛛每次都返回{'address': []}。我认为我告诉它提取数据的方式可能有问题..

更新:

看起来它没有提取任何数据,因为请求在“#”处被切断

RESPONSE: <200 https://property.spatialest.com/nc/durham/>
2019-03-16 13:59:12 [scrapy.core.scraper] DEBUG: Scraped from <200 https://property.spatialest.com/nc/durham/>
{'address': []}```

【问题讨论】:

标签: python scrapy web-crawler


【解决方案1】:

该网站使用额外的请求来返回您需要的数据。

如果您打开开发者工具,您可以看到返回您需要的数据的请求。

网址:https://property.spatialest.com/nc/durham/data/propertycard

方法:POST

正文:parcelid=100016&amp;card=&amp;year=&amp;debug%5BcurrentURL%5D=https%3A%2F%2Fproperty.spatialest.com%2Fnc%2Fdurham%2F%23%2Fproperty%2F100016&amp;debug%5BpreviousURL%22%5D=

响应是json,你可以在这里找到所有数据。

所以你应该在scrapy里面提出请求来获取数据

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 2015-09-23
    相关资源
    最近更新 更多