python下载链接内容

下面代码下载京东注册码,可接收参数num dir

可以将连接构造成其它网址,比如移动联通网上营业厅的验证码都是固定网址+13位时间戳的结构。

#!/usr/bin/python
#code utf-8
import urllib
import time
import sys
import os

urlbase = 'https://authcode.jd.com/verify/image?a=0&acid=52b9316d-c9ab-4169-b39e-1217deaede7b&uid=52b9316d-c9ab-4169-b39' \
          'e-1217deaede7b&srcid=reg&is=7c63fc289d9ce9f3ba8304f74c1b9f19&yys='

picnum = 10
filedir = os.getcwd() + '/'
lenarg = len(sys.argv)
if lenarg == 2:
    picnum = int(sys.argv[1])
elif lenarg == 3:
    picnum,filedir = int(sys.argv[1]), filedir+str(sys.argv[2])+'/'

print 'file save at',filedir

for _ in range(picnum):
    t = str(int(round(time.time()*1000)))
    urllink = urlbase + t
    print urllink
    filename = filedir + t + '.jpg'
    urllib.urlretrieve(urllink, filename)

 

posted @ 2017-04-07 18:30  柳如风  阅读(1309)  评论(0编辑  收藏  举报
https://www.vultr.com/?ref=7677570