2017年6月 抓取知乎某一问题下所有答案图片
来源:互联网 发布:历史的巧合 知乎 编辑:程序博客网 时间:2024/05/21 09:10
#抓取其他问题自己修改geturl中答案问题id就行
#! /usr/bin/env python
from urlparse import urlsplit
from os.path import basename
import urllib2
import re
import requests
import os
import json
import urllib
if not os.path.exists('images'):
os.mkdir("images")
page_size = 50
offset = 0
x=0
id=37787176
url = 'https://www.zhihu.com/question/37787176'
url_content = urllib2.urlopen(url).read()
while offset < 100:
get_url = 'https://www.zhihu.com/api/v4/questions/37787176/answers?sort_by=default&include=data%5B%2A%5D.is_normal%2Cis_sticky%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Crelationship.is_authorized%2Cis_author%2Cvoting%2Cis_thanked%2Cis_nothelp%2Cupvoted_followees%3Bdata%5B%2A%5D.author.badge%5B%3F%28type%3Dbest_answerer%29%5D.topics&limit=20&offset='+str(offset)
header = {
'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0",
'Host': "www.zhihu.com",
'Referer': "https://www.zhihu.com/question/37787176",
'Authorization' :"Bearer Mi4wQUJDTXVUc0Y5QWdBSUFMS0RiVk5DeGNBQUFCaEFsVk4tQTFiV1FBZVpkaHBZRTFDWVh3OXJtZlpGa0x2MkpfSk9n|1497494260|7cc3b8925cfc9e47ef0e2bb6a8e96d45827deb2d"
}
req = urllib2.Request(get_url, headers = header)
response=urllib2.urlopen(req).read()
txt=json.loads(response)
print txt
offset += 20
img_urls = re.findall('img .*?src="(.*?_b.*?)"', str(txt))
for img_url in img_urls:
try:
x+= 1
img_data = urllib2.urlopen(img_url).read()
# file_name = basename(urlsplit(img_url)[2])
output = open('images/' +str(x), 'wb')
output.write(img_data)
output.close()
except:
pass
print x
#! /usr/bin/env python
from urlparse import urlsplit
from os.path import basename
import urllib2
import re
import requests
import os
import json
import urllib
if not os.path.exists('images'):
os.mkdir("images")
page_size = 50
offset = 0
x=0
id=37787176
url = 'https://www.zhihu.com/question/37787176'
url_content = urllib2.urlopen(url).read()
while offset < 100:
get_url = 'https://www.zhihu.com/api/v4/questions/37787176/answers?sort_by=default&include=data%5B%2A%5D.is_normal%2Cis_sticky%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Crelationship.is_authorized%2Cis_author%2Cvoting%2Cis_thanked%2Cis_nothelp%2Cupvoted_followees%3Bdata%5B%2A%5D.author.badge%5B%3F%28type%3Dbest_answerer%29%5D.topics&limit=20&offset='+str(offset)
header = {
'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0",
'Host': "www.zhihu.com",
'Referer': "https://www.zhihu.com/question/37787176",
'Authorization' :"Bearer Mi4wQUJDTXVUc0Y5QWdBSUFMS0RiVk5DeGNBQUFCaEFsVk4tQTFiV1FBZVpkaHBZRTFDWVh3OXJtZlpGa0x2MkpfSk9n|1497494260|7cc3b8925cfc9e47ef0e2bb6a8e96d45827deb2d"
}
req = urllib2.Request(get_url, headers = header)
response=urllib2.urlopen(req).read()
txt=json.loads(response)
print txt
offset += 20
img_urls = re.findall('img .*?src="(.*?_b.*?)"', str(txt))
for img_url in img_urls:
try:
x+= 1
img_data = urllib2.urlopen(img_url).read()
# file_name = basename(urlsplit(img_url)[2])
output = open('images/' +str(x), 'wb')
output.write(img_data)
output.close()
except:
pass
print x
阅读全文
0 0
- 2017年6月 抓取知乎某一问题下所有答案图片
- Python抓取知乎答案内容
- Java知乎爬虫之抓取知乎答案
- 用python爬虫抓取知乎图片
- Python爬虫之知乎图片抓取
- 零基础写Java知乎爬虫之抓取知乎答案
- 零基础写Java知乎爬虫之抓取知乎答案
- python下载知乎某个问题下的全部图片
- 遍历某一folder下所有的图片
- python 抓取知乎
- 知乎上一个关于Android面试的问题答案
- 第一篇哦~~知乎问题答案分析
- python Requests 知乎问题图片爬虫
- 求某一年的某一月有多少天问题
- Python爬虫对知乎问题下的图片进行爬取
- 如何高效的抓取iOS下ipa的所有图片
- 被管理员和谐了的最高票答案“知乎数据抓取程序”(.net、c#数据挖掘)
- 知乎图片爬虫
- 【笔记】laravel上传文件
- JAVA反射技术
- C++万年历
- tp分页------注意page->firstRow 后面没括号
- CSDN-markdown编辑器使用宝典
- 2017年6月 抓取知乎某一问题下所有答案图片
- SQlite数据库(2)----android 操作
- 设计更好的表格
- Maven下SpringMVC简单例子
- hdoj 1686 Oulipo
- 发送有序广播
- select实现并发服务器
- Master深度剖析
- java.lang.NullPointerException: Attempt to get length of null array的解决方法