Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get the http Header Information for web scraping

I am new to web scraping,
How can i get the product ID from the HTTP header (screenshot attached)

source : https://www.pickaboo.com/product-detail/samsung-galaxy-a03-3gb-32gb/

I am using requests to get the information but still no luck.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

url = 'https://www.pickaboo.com/product-detail/samsung-galaxy-a04-3gb-32gb/'
requests.get(url)

I got all the information except review section.

Screenshot

>Solution :

The product ID is stored on the main page inside <script> element. To get it you can use next example:

import json
import requests
from bs4 import BeautifulSoup

url = 'https://www.pickaboo.com/product-detail/samsung-galaxy-a03-3gb-32gb/'

soup = BeautifulSoup(requests.get(url).content, 'html.parser')
data = soup.select_one('#__NEXT_DATA__')
data = json.loads(data.text)

# uncomment this to print all data:
# print(json.dumps(data, indent=4))

print(data['props']['pageProps']['product']['id'])

Prints:

85397

Note: On your screenshot is not shown HTTP header but URL parameter.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading