python获取html解析

2018-10-09  本文已影响0人  IthinkIcanfly

打开一个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)
上一篇 下一篇

猜你喜欢

热点阅读