使用Scrapy从web应用程序中获取dinamic数据

2024-09-30 12:30:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从这个网站上获取数据:https://www.icostats.com。问题是数据似乎是用JS生成的。在

我使用ScrapyJS从列中获取数据(例如“Change(%)”)并将其导出到json文件中。到目前为止,除了[{"text": null}]之外,我无法获得任何其他输出。是我搞砸了还是做不到?在

我的代码:

import scrapy

class ICOSpider(scrapy.Spider):
    name = "icoo"
    allowed_domains = ["icostats.com"]
    start_urls = [
        'https://icostats.com',
    ]

    def start_requests(self):
        for url in self.start_urls:
            yield scrapy.Request(url, self.parse, meta={
                'splash': {
                    'endpoint': 'render.html',
                    'args': {'wait': 0.5}
                }
            })

    def parse(self, response):
        for ico in response.css('div#app'):
            yield {
                'text': ico.css('div.data-reactroot container-0-16 table-0-20 tableheader-0-50 tr-0-68 td-0-69 tdName-0-73::text').extract_first(),

            }

爬网命令:$ scrapy crawl icoo -o ico.json


Tags: textinhttpsselfcomjsonurlfor

热门问题