Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
How to scrape JavaScript rendered data from a website using Scrapy?

Using Scrapy, I'm trying to scrape data of tag <script type="application/ld+json">....

import json

class TestSpider(scrapy.Spider):
    name = 'content'
    start_urls = ['https://www.maserati.com/us/en/models/ghibli']

    def parse(self, response):
        for content in response.xpath('(//script[@type="application/ld+json"])/text()'):
            data = json.loads(content)
            yield {
                'name': data['name'],
            }

        next_page = response.css('li.next a::attr("href")').get()
        if next_page is not None:
            yield response.follow(next_page, self.parse)

However, I'm not getting the test1.jl file that I was expecting once after writing, scrapy runspider test_spider.py - O test1.jl in the terminal

I just want the name for a start to know how it works.

Image and website link for inspection are given below:

Image that shows the javascript tag and the name property inside that I want to yield

Image of my code and the code in the terminal

https://www.maserati.com/us/en/models/ghibli

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You were so close...just missing getall()

import scrapy
import json


class TestSpider(scrapy.Spider):
    name = 'content'
    start_urls = ['https://www.maserati.com/us/en/models/ghibli']

    def parse(self, response):
        for content in response.xpath('(//script[@type="application/ld+json"])/text()').getall():
            data = json.loads(content)
            yield {
                'name': data['name'],
            }

        next_page = response.css('li.next a::attr("href")').get()
        if next_page is not None:
            yield response.follow(next_page, self.parse)

(I don't see any "next" button though)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda