seanhuai / tumblr-source-list Goto Github PK
View Code? Open in Web Editor NEW一个Tumblr资源工具,用于获取图片或视频信息
Home Page: https://seanhuai.github.io/2017/08/tumblr-source-list
License: MIT License
一个Tumblr资源工具,用于获取图片或视频信息
Home Page: https://seanhuai.github.io/2017/08/tumblr-source-list
License: MIT License
app.py username xxxxx photo 1
limit参数输入1,发现并不是只获取了第一页的图片,还获取到了第二页,第三页的部分图片。
api 中offset 参数并不是多少也 这个值是从那个位置其后20条记录
我根据您的代码我修改了下 获取这个博客的所有posts 内的vedio 或者phtoto
from urllib import request
import json
proxy_handler = request.ProxyHandler({'http': 'http://127.0.0.1:1080/'})
opener = request.build_opener(proxy_handler)
url = 'http://api.tumblr.com/v2/blog/{username}.tumblr.com/posts/{mediatype}?api_key=fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4&offset={offset}'
infourl = 'http://api.tumblr.com/v2/blog/{username}.tumblr.com/info?api_key=fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4'
username = 'wsyghf'
mediatype='video'
f = opener.open(infourl.format(username=username))
j_f = json.loads(f.read())
print(j_f)
total_posts = j_f['response']['blog']['total_posts']
urls = []
for i in range(int(total_posts/20)+1):
urls.append(url.format(username=username, mediatype=mediatype, offset=i*20))
def get_v(url):
f = opener.open(url)
d1 = json.load(f)
v = []
for i in d1['response']['posts']:
if mediatype == 'video':
v.append(i['video_url'])
else:
for i1 in i['photos']:
v.append(i1['original_size']['url'])
return v
c = {}
for u in urls:
for cc in get_v(u):
c[cc] = ''
print(c)
with open('all{username}_{mediatype}.txt'.format(mediatype=mediatype, username=username), 'w') as f:
for u1 in c.keys():
f.write(u1+'\n')
PS E:\code\git\tumblr-source-list> python .\app.py posturl https://wsyghf.tumblr.com/post/150478441406/
Traceback (most recent call last):
File ".\app.py", line 5, in
from packages._funcs import *
File "E:\code\git\tumblr-source-list\packages_funcs.py", line 3, in
from packages._proxy import *
File "E:\code\git\tumblr-source-list\packages_proxy.py", line 3, in
from urllib import request
ImportError: cannot import name request
这是我的命令行信息,请问是什么问题导致的?这个脚本使用的python版本是多少呢~
谢谢~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.