Skip to content Skip to sidebar Skip to footer

Unable To Capture Records Name , Price And Rating And Image In Requests Python

Exception occur when printing the productname, product size price and rating here is the link from which i want to extract the details. import requests import time from requests.m

Solution 1:

You have to scrape the adidas site and use regex:

import requests
import re

endpoint = "https://www.adidas.com.au/continental-80-shoes/G27707.html"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
response = requests.get(endpoint, headers = headers)
data = response.text

pricereg = r"(?<=\"price\":)(.*)(?=,\")"
namereg = r"(?<=\"name\":)(.*)(?=,\"co)"
ratingreg= r"(?<=\"ratingValue\":)(.*)(?=,\"reviewCou)"

price = re.search(pricereg, data, re.MULTILINE).group()
name = re.search(namereg, data, re.MULTILINE).group()
rating = re.search(ratingreg, data, re.MULTILINE).group()

print(f"name {name}, rating {rating}, price {price}")

Post a Comment for "Unable To Capture Records Name , Price And Rating And Image In Requests Python"