Home > database >  Scrapy response.xpath how to get the number output
Scrapy response.xpath how to get the number output

Time:11-18

I want to get in Scrapy a numeric value instead of text. Please see in the code "result-number-lg btn-number-details" - the output 0156 numeric value. How do I do it?

I have try

response.xpath('//span[contains(@data-prize-type,"1")]/text()').getall()

the output is {FirstPrize} instead of 0156.

0156

enter image description here

FirstPrize

CodePudding user response:

Data is loaded dynamically by javascript. That's why to grab the desired data you have to use an automation tool something like selenium. Here I use selenium and getting the desired output as follows:

import time
from selenium import webdriver

driver = webdriver.Chrome('chromedriver.exe')
url = "https://www.magnum4d.my/en/results"
driver.get(url)
time.sleep(15)

values =driver.find_elements_by_xpath('//*[@]')

for v in values:
    print(v.text)  

Output:

0156
0590
6894
5691
4449
2699
7762
2968
9727
  • Related