python三方库之BeautifuSoup
发布日期:2021-05-07 18:07:10 浏览次数:30 分类:技术文章

本文共 468 字,大约阅读时间需要 1 分钟。

html文档解析的三方库beautifulsoup4

什么是beautifulsoup?

学习资源:

1.安装

pip install beautifulsoup4

2.使用

至少要对html有一定的了解。

from bs4 import BeautifulSoup

举例:获取一个页面中的所有链接

def get_link(url="http://www.zhihu.com"):    hrefs = []    html = urllib2.urlopen(url=url).read()    soup = BeautifulSoup(html, "html.parser")    for link in soup.find_all('a'):        href = link.get('href')        if not href.startswith('http'):            href = url + href        hrefs.append(href)    return hrefs

上一篇:coddenomicon工具
下一篇:CSS层叠样式表

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年03月22日 12时58分34秒