知乎抓图python脚本
来源:互联网 发布:vscode php格式化插件 编辑:程序博客网 时间:2024/06/07 06:29
- 填写知乎的question_id
- 填写图片保存的路径
- 运行脚本
#! /usr/bin/env pythonfrom urlparse import urlsplitfrom os.path import basenameimport urllib2import reimport requestsimport osimport jsonquestion_id = '30137203'pic_path = '/Users/xxx/Desktop/pic/'url = 'https://www.zhihu.com/question/' + question_idif not os.path.exists(pic_path): os.mkdir(pic_path)page_size = 50offset = 0url_content = urllib2.urlopen(url).read()answers = re.findall('h3 data-num="(.*?)"', url_content)print answerslimits = int(answers[0])while offset < limits: post_url = "http://www.zhihu.com/node/QuestionAnswerListV2" params = json.dumps({ 'url_token': question_id, 'pagesize': page_size, 'offset': offset }) data = { '_xsrf': '', 'method': 'next', 'params': params } header = { 'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0", 'Host': "www.zhihu.com", 'Referer': url } response = requests.post(post_url, data=data, headers=header) answer_list = response.json()["msg"] img_urls = re.findall('img .*?src="(.*?_b.*?)"', ''.join(answer_list)) for img_url in img_urls: try: img_data = urllib2.urlopen(img_url).read() file_name = basename(urlsplit(img_url)[2]) output = open(pic_path + file_name, 'wb') print file_name output.write(img_data) output.close() except: pass offset += page_size
0 0
- 知乎抓图python脚本
- python脚本
- Python脚本
- python 脚本
- python脚本
- python脚本
- python脚本
- python脚本
- Python脚本
- python脚本
- Python脚本 基础脚本训练
- 爬虫/脚本/Python语言- 脚本
- python脚本中启动另一个python脚本
- 【python】crontab调用python脚本
- Python:定时运行脚本
- 如何执行python脚本
- IIS 使用 Python 脚本
- python脚本文件批量改名
- li中包含div内容越界问题
- ALAssetsLibrary 读取所有照片
- synchronized的实现用了自旋锁还是互斥锁?
- TabLayout + ViewPager + Fragment 实现布局
- C#之委托
- 知乎抓图python脚本
- iOS UITextField 只能输入数字和小数点,只能有两位小数
- Crontab的格式
- C/C++ 宏定义中#与##区别
- android图片素材参考
- 详解Android动画之 属性动画(Property Animation) 完全解析 (上)
- 1-渗透测试技术基础
- Openstack:Nova中“从云硬盘启动”、“从镜像启动”、“从镜像启动(创建一个卷)”_prep_block_device中的差异
- dbca识别不到已经存在的数据库