how can extract the href content, im using python 2.7 and bs4
<h2 class ="product-card__title" >
<a class ="link product-card__title-link" href="theping" >kik</a>
</h2>
I have this code, im extracting the kik text easy, but i cant extract the href
find = soup.find_all('h2', {'class' : 'product-card__title'}, limit=None)
for a in find:
title = a.text.strip()
print title
url = a.find('a[href]')
print url
this is a part code, title print perfect but url show me none.... some idea?
for h2 in soup.find_all('h2', {'class' : 'product-card__title'}, limit=None):
print h2.a['href']
Source: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
Change below line:
url = a.find('a[href]')
to
url = aa[href]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.