回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我对python很陌生。。。在</p>
<pre><code> import sys, os, time, py4chan, urllib from urllib2 import urlopen, URLError, HTTPError
def refreshthread(boardin,no):
global thread
global topic
board = py4chan.Board(boardin)
thread = board.getThread(int(no))
topic = thread.topic
time.sleep(2.5)
def dlfile(url, folder):
try:
f = urlopen(url)
with open(folder + "/" + os.path.basename(url), "wb") as local_file:
local_file.write(f.read())
print "Downloaded to " + str(folder + "/" + os.path.basename(url))
except HTTPError, e:
print "HTTP Error:", e.code, url
except URLError, e:
print "URL Error:", e.reason, url
def getsize(uri):
file = urllib.urlopen(uri)
size = file.headers.get("content-length")
file.close()
return str(int(size) / 1024)
def main():
boardtag = str(raw_input("Board: "))
threadno = int(raw_input("Thread id: "))
folder = str(raw_input("Save to folder: "))
print "Getting thread information..."
refreshthread(boardtag,threadno)
print "Subject: " + topic.Subject
while(True):
if not os.path.exists(folder): os.makedirs(folder)
refreshthread(boardtag,threadno)
for imgurl in thread.Files():
if imgurl is not None and not os.path.exists(folder + "/" + os.path.basename(imgurl)):
print "A wild image appears! " + "(" + getsize(imgurl) + "kb)"
dlfile(imgurl,folder)
else:
pass
if __name__ == '__main__':
main()
</code></pre>
<p>我在linux上编写了这个代码,它运行得很好,但是如果我在windows上运行,就会出现以下错误:</p>
^{pr2}$
<p>这很奇怪,因为我还没有定义<strong>init</strong>。
这可能是来自另一个模块的<strong>init</strong>?在</p>
<p>如果我编写其他脚本,py4chan模块似乎可以正常工作。
两台机器的python版本也相同。在</p>
<p><strong>编辑</strong>(完全错误):</p>
<pre><code>Getting thread information...
Traceback (most recent call last):
File "4chan.py", line 59, in <module>
main()
File "4chan.py", line 46, in main
refreshthread(boardtag,threadno)
File "4chan.py", line 15, in refreshthread
board = py4chan.Board(boardin)
TypeError: __init__() takes exactly 4 arguments (2 given)
</code></pre>
<p>*<em>编辑:</em>*好吧,我有两个同名的不同模块。现在都在工作。
我不应该被允许进入这个网站。在</p>