Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to find text of h2 tag in python requests-html

# importing the HTMLSession class
from requests_html import HTMLSession
# create the object of the session
session = HTMLSession()
# url of the page
web_page = 'https://www.investopedia.com/terms/s/sample.asp'
# making get request to the webpage
respone = session.get(web_page)
# getting the html of the page
page_html = respone.html
# finding all h2 tags
h2_tags= page_html.find('h2')
# extracting text from all h2 tags
for tag in h2_tags:
    print(tag.text)Copy Code
Source by www.alixaprodev.com #
 
PREVIOUS NEXT
Tagged: #How #find #text #tag #python
ADD COMMENT
Topic
Name
1+1 =