Home > Blockchain >  How to scrape h2 tag with data-wipe-name?
How to scrape h2 tag with data-wipe-name?

Time:10-03

I am new to scraping. I am trying to scrape the following data. but I could not find a way to do that. Can somebody help me with that? <h2 data-wipe-name='Titel'>Company name</h2> I want to extract this Company Name.

CodePudding user response:

Welcome to - You should improve your question but a possible solution can be the following.

Solution

Select tag and it´s attribute, then get the text:

from bs4 import BeautifulSoup

html_text='''<h2 data-wipe-name='Titel'>Company name</h2>'''
soup= BeautifulSoup (html_text,'lxml')

soup.select_one('h2[data-wipe-name="Titel"]').get_text()

Output

Company name

CodePudding user response:

You can do that using find method as follows:

Code:

from bs4 import BeautifulSoup

h2_tag ='''<h2 data-wipe-name='Titel'>Company name</h2>'''
soup= BeautifulSoup (h2_tag,'html.parser')

h2_text = soup.find('h2', {'data-wipe-name':'Titel'}).text
print(h2_text)

Output:

Company name
  • Related