python使用BeautifulSoup分页网页中超链接的方法
本文实例讲述了python使用BeautifulSoup分页网页中超链接的方法。分享给大家供大家参考。具体如下:
python通过BeautifulSoup分页网页中的超级链接,这段python代码输出www.nhooo.com主页上所有包含了jb51的url链接
fromBeautifulSoupimportBeautifulSoup
importurllib2
importre
url=urllib2.urlopen("https://www.nhooo.com")
content=url.read()
soup=BeautifulSoup(content)
forainsoup.findAll('a',href=True):
ifre.findall('sharejs',a['href']):
print"FoundtheURL:",a['href']
希望本文所述对大家的Python程序设计有所帮助。