Python中文
首页
教程
问答
标签
搜索
登录
注册
为什么这个imagedownloadscript不起作用?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一个密码和一个问题。你知道吗</p> <p/> <pre><code>import string import random import httplib import urllib import os import sys import inspect def id_generator(size=5, chars=string.ascii_letters + string.digits): return ''.join(random.choice(chars) for _ in range(size)) picnumber = raw_input('Please enter the amount of images you want!') nothingfoundnumber=0 foundnummer=0 scriptpath = os.path.dirname(sys.argv[0]) filename = scriptpath + "/output/" if not os.path.exists(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename)) while foundnummer != picnumber: randompicstring = id_generator() print "Trying " + str(randompicstring) try: urllib.urlretrieve("http://i.imgur.com/" +randompicstring+ ".gif", "/test/" +randompicstring + ".gif") foundnummer+=1 print str(randompicstring) + "was found! Makes " +str(foundnummer)+ " out of " +str(picnumber)+"!" except IOError: nothingfoundnumber+=1 print str(randompicstring) + "not found. It was the "+str(nothingfoundnumber)+" try." </code></pre> <p>这样做的目的是尝试随机组合的腹水和数字,以找到图像上imgur.com(例如<a href="http://i.imgur.com/XgEVx.png" rel="nofollow">http://i.imgur.com/XgEVx.png</a>)。如果它发现了什么,它应该说,并保存图像和增加foundnumber。如果它没有找到一个图像,它应该这样说,并增加nothingfoundnumber。你知道吗</p> <p>现在它不起作用,它只是说它总是找到一些东西,什么也不保存。 有人能帮我修一下吗?你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您可能还应该考虑使用<a href="https://api.imgur.com/" rel="nofollow">Imgur API</a>,而不是生成随机字符串。看起来随机图像有一个端点。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
我是否正确构建了这个递归神经网络
6 回答
我是否正确理解acquire和realease是如何在python库“线程化”中工作的
1 回答
我是否正确理解Keras中的批次大小?
8 回答
我是否正确理解PyTorch的加法和乘法?
8 回答
我是否正确组织了我的Django应用程序?
6 回答
我是否正确计算执行时间?如果是这样,那么并行处理将花费更长的时间。这看起来很奇怪
10 回答
我是否每次创建新项目时都必须在PyCharm中安装numpy?(安装而不是导入)
10 回答
我是否每次运行jupyter笔记本时都必须重新启动内核?
8 回答
我是否用python安装了socks模块?
3 回答
我是否真的需要知道超过一种语言,如果我想要制作网页应用程序?
6 回答
我是否缺少spaCy柠檬化中的预处理功能?
3 回答
我是否缺少给定状态下操作的检查?
1 回答
我是否能够使用函数“count()”来查找密码中大写字母的数量((Python)
10 回答
我是否能够使用用户输入作为colorama模块中的颜色?
6 回答
我是否能够创建一个能够添加新Django.contrib.auth公司没有登录到管理面板的用户?
3 回答
我是否能够将来自多个不同网站的数据合并到一个csv文件中?
8 回答
我是否能够将目录路径转换为可以输入python hdf5数据表的内容?
3 回答
我是否能够等到一个对象被销毁,直到它创建另一个对象,然后在循环中运行time.sleep()
1 回答
我是否能够通过CBV创建用户实例,而不是首先创建表单?(Django)
2 回答
我是否要使它成为递归函数?
2 回答