无为清净楼资源网 Design By www.qnjia.com
网址:https://www.toutiao.com/
搜索头条
可以得到这个网址:
https://www.toutiao.com/search/"text-align: center">
我们在搜索中并没有发现上面的文字,那么我们可以初步判定,这个由Ajax加载,然后渲染出来的。此时切换到xhr过滤,可以看到确实是ajax请求。
观察请求的特点,发现只有offset是改变的,而且一次加20,。
我们可以用它来控制数据分页,然后把图片下载下来。代码如下:
import requests import os from urllib.parse import urlencode from hashlib import md5 from multiprocessing.pool import Pool from requests import codes def get_page(offset): params = { "offset":offset, "format":"json", "keyword":"街拍", "autoload":"true", "count":"20", "cur_tab":"1", "from":"search_tab" } url = 'https://www.toutiao.com/search_content/?'+urlencode(params) try: response = requests.get(url) if response.status_code == 200: # print(url) return response.json() except requests.ConnectionError: return None # get_page(0) def get_images(json): if json.get('data'): for item in json.get('data'): if item.get('cell_type') is not None: continue title = item.get('title') images = item.get('image_list') for image in images: yield { 'title':title, 'image':'https:' + image.get('url'), } def save_image(item): #os.path.sep 路径分隔符‘//' img_path = 'img' + os.path.sep + item.get('title') if not os.path.exists(img_path): os.makedirs(img_path) try: resp = requests.get(item.get('image')) # print(type(resp)) if codes.ok == resp.status_code: file_path = img_path + os.path.sep + '{file_name}.{file_suffix}'.format( file_name=md5(resp.content).hexdigest(),#md5是一种加密算法获取图片的二进制数据,以二进制形式写入文件 file_suffix='jpg') if not os.path.exists(file_path): with open(file_path,'wb')as f: f.write(resp.content) print('Downladed image path is %s' % file_path) else: print('Already Downloaded',file_path) except requests.ConnectionError: print('Failed to Save Image,item %s' % item) def main(offset): json = get_page(offset) for item in get_images(json): print(item) save_image(item) GROUP = 0 GROUP_END = 2 if __name__ == '__main__': pool = Pool() groups = ([x*20 for x in range(GROUP,GROUP_END)]) pool.map(main,groups) #将groups一个个调出来传给main函数 pool.close() pool.join() #保证子进程结束后再向下执行 pool.join(1) 等待一秒
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年09月21日
2024年09月21日
- 王菲.1996-《乐乐精逊SACD日本限量版[WAV+CUE]
- 不止黑神话!杭州给原创企业真金白银扶持 打造“杭州游戏”品牌
- 很有多样性:《战锤》首次引入非二元性别角色
- 《少女前线2:追放》项目组将裁员 官方:进一步优化组织结构
- 陈慧琳.2002-闪亮每一天新歌+精选2CD【正东】【WAV+CUE】
- 袁培华.1992-有缘【歌林】【WAV+CUE】
- 王瑞霞.1996-是我太软心【名冠】【WAV+CUE】
- 《谭维维 30首经典流行歌曲精选辑 2CD》[WAV/分轨][1.1GB]
- 《赵传 出道三十年全新大碟 你过得还好吗》[WAV/分轨][460MB]
- 《发烧四大天王 磁性男声HiFi发烧碟 2CD》[WAV/分轨][1GB]
- 黑神话悟空上品鼠司空精魄获取方法一览|上品鼠司空精魄收集攻略
- 《真三国无双:起源》新情报将于9月26日公开,实机演示亮相!
- 黑神话悟空上品鼠禁卫精魄获取方法一览|上品鼠禁卫精魄收集攻略
- 优美的旋律至真的情怀《品茶轻音乐·极品典藏Vol.1CD1》[WAV+CUE]
- 曾嵘《峥嵘岁月DSD(试音碟)》WAV+CUE