引言:刚开始我想要爬取微博的照片,但是发现网上大多数的blog都是需要一个cookie的东西,当时我很难得到,偶然翻到一个个人的技术博客: http://www.omegaxyz.com/2018/02/13/python_weibo/ (顺便推荐一下他的博客吧,里面有很多干货))) 试了一下,效果还是很好的:
# -*- coding: utf-8 -*-
import urllib.request
import json
import requests
import os
path = 'D:\\picture\\weibo\\'
#id = '2093492691'
id = '2374240301'
proxy_addr = "122.241.72.191:808"
pic_num = 0
weibo_name = "programmer"
def use_proxy(url, proxy_addr):
req = urllib.request.Request(url)
req.add_header("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0")
proxy = urllib.request.ProxyHandler({
'http': proxy_addr})
opener = urllib.request.build_opener(proxy, urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
data = urllib.request.urlopen(req).read().decode('utf-8', 'ignore')
return data
def get_containerid(url):
data = use_proxy(url, proxy_addr)
content = json.loads(data).get('data')
for data in content.get('tabsInfo').get('tabs'):
if (data.get('tab_type') == 'weibo'):
containerid = data.get('containerid')
return containerid
def get_userInfo(id):
url
|