如何获取href标签中的链接?我如何编码它似乎整个' a'标签... 代码:
page = urllib2.urlopen('https://www.meetup.com/')
soup = BeautifulSoup(page, 'lxml')
categories = soup.find('ul', class_='gridList')
A = []
B = []
for category in categories.findAll('li'):
text = category.findAll('h4')
if len(text) != 0:
A.append(text[0].find(text = True))
for link in categories.findAll('li'):
url = link.findAll('a', href=True)
if len(url) != 0:
B.append(url)
答案 0 :(得分:0)
...
(your code above)
for link in categories.findAll('li'):
url = link.find('a', href=True)
if len(url) != 0:
B.append(url['href'])