0

i have a page where i want to extract a ean number from a script tag (here it is 8806090571589)

I tried to get the script firstly with

        jsonn = r.html.find('script')[3].text
        print(title, price, jsonn)

however that didnt work.

the source code of the page is on here (too long to post):

view-source:https://www.kaufland.de/product/361834606/?search_value=waschmaschine

1 Answer 1

2

When you use find(), it will return only the first occurrence of the tag. Since I can see that you need to find the 4th occurrence, you need to use the findAll() function. It will return a list of all the occurrences and then you can use any occurrence according to your needs.

I've tried using the below given code on my computer -

import urllib3
from bs4 import BeautifulSoup

URL = "https://www.kaufland.de/product/361834606/?search_value=waschmaschine"

response = urllib3.PoolManager().request("GET", URL, headers={'User-Agent' : "python"})
soup = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')

print(soup.findAll("script")[3])

You can take this code for reference and modify as per your needs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.