用到的主要知识点:requests.get 获取网页HTMLetree.HTML 使用lxml解析器解析网页xpath 使用xpath获取网页标签信息.图片地址request.urlretrieve 下载图片(注:该网站使用urlretrieve下载图片时,返回403错误.原因目前未知!) 改用 with as 下载图片:with open('文件地址及名字', 'wb') as f: f.write(res.content) 详细代码如下: #!/user/bin env python # a
从一个网页爬取图片已经解决,现在想要把这个用户发的图片全部爬取. 首先:先找到这个用户的发帖页面: http://www.acfun.cn/u/1094623.aspx#page=1 然后从这个页面中爬取每个帖子页面的链接 然后重复(一)的过程 源码: from urllib.request import urlopen from urllib.request import urlretrieve from bs4 import BeautifulSoup as da import re imp