从filesonic下载文件的脚本
有人能告诉我怎么写一个Python脚本来完成以下几件事吗?
- 把我的IP地址换成一个随机的代理地址。
- 下载并显示验证码图片,并给我一个可以输入验证码的提示框。
- 下载主要文件。
这个脚本应该有一个输入参数(地址类似于以下这些):
http://www.filesonic.com/file/212720521/Ubuntu.11.04.part1.rar
http://www.filesonic.com/file/212720541/Ubuntu.11.04.part2.rar
这个脚本会被调用两次,如下所示:
python dlsonic.py http://www.filesonic.com/file/212720521/Ubuntu.11.04.part1.rar
python dlsonic.py http://www.filesonic.com/file/212720541/Ubuntu.11.04.part2.rar
1 个回答
2
这里有一些基本的Python代码,可以帮助你入门:
import urllib2
response = urllib2.urlopen('http://www.example.com/')
html = response.read() # This is what is read from the file. In your case,
# it'll only read the contents of the webpage.
要更改你的IP地址,你可以使用一些Linux命令来实现这个(假设你是在用以太网):
ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up
ifconfig eth0
在Python中,你可以用 os.system()
来运行这些命令:
import os
os.system('ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up')
os.system('ifconfig eth0')
如果你想处理命令行参数,比如 python foo.py bar foo bar bar
,可以这样做:
import sys
print sys.argv
至于处理验证码,这会比较棘手。你确定不能手动完成这个吗?