find - Capturing data between specific tag in python -


i getting url content in python... want capture between <h1> , </h1>.

what tried is:

mystring='''<h1>kgkgjgjgkjgkjgkj</h1> <h1>kdfgggggggggggggggggggkgjgjgkjgkjgkj</h1> dsfgdfgg <h1>kgkgjgjgkdfgdfgdgdfjgkjgkj</h1> dfgdffdgf <h1>kgkgjgjsdssssssssssssssssssssgkjgkjgkj</h1> dfgdfgdg <h1>kgkgjgjgkjgkjgkgggggggggggggggggggj</h1> ''' if '<h1>' in mystring:     startstring='<h1>'     endstring='</h1>'     print mystring[mystring.find(startstring)+len(startstring):mystring.find(endstring)] 

i have multiple h1 tags. capture data between first h1 tag.

how can capture data between h1 tags?

i go beautifulsoup-- attempt

from bs4 import beautifulsoup import requests  url = 'http://accessibility.psu.edu/headingshtml/'  respons = requests.get(url).content  soup = beautifulsoup(respons,'lxml')  h1tags = soup.find_all('h1')  singletag in h1tags:     print singletag.text 

prints ( in case 1 h1 tag)

heading tags (h1, h2, h3, p) in html 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -