Extract text between link tags in python using BeautifulSoup -


i have html code this:

<h2 class="title"><a href="http://www.gurletins.com">my homepage</a></h2>

<h2 class="title"><a href="http://www.gurletins.com/sections">sections</a></h2>

i need extract texts (link descriptions) between 'a' tags. need array store these like:

a[0] = "my homepage"

a[1] = "sections"

i need in python using beautifulsoup.

please me, thank you!

you can this:

import beautifulsoup  html = """ <html><head></head> <body> <h2 class='title'><a href='http://www.gurletins.com'>my homepage</a></h2> <h2 class='title'><a href='http://www.gurletins.com/sections'>sections</a></h2> </body> </html> """  soup = beautifulsoup.beautifulsoup(html)  print [elm.a.text elm in soup.findall('h2', {'class': 'title'})] # output: [u'my homepage', u'sections'] 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -