美文网首页
python获取html解析

python获取html解析

作者: IthinkIcanfly | 来源:发表于2018-10-09 15:39 被阅读0次

打开一个url

from urllib.request import urlopen
html = urlopen(url)

解析html元素编程对象

from bs4 import BeautifulSoup
bsobj = BeautifulSoup(html.read())

查找元素

title = bsobj.findAll("img")

查找元素的属性

image[i].attrs['src']

下载文件

from urllib.request import urlretrieve
urlretrieve(img_url, file_name)

相关文章

网友评论

      本文标题:python获取html解析

      本文链接:https://www.haomeiwen.com/subject/evtyaftx.html