Skip to content

Instantly share code, notes, and snippets.

@jerryan999
Created October 25, 2020 11:45
Show Gist options
  • Save jerryan999/cf76df79543b675b781f4ba2c0d4d378 to your computer and use it in GitHub Desktop.
Save jerryan999/cf76df79543b675b781f4ba2c0d4d378 to your computer and use it in GitHub Desktop.
download captcha image for training study
import requests
import urllib
import json
import uuid
import os
image_folder = "images"
def save_image():
# token to download
token_url = "https://passport.youzan.com/api/captcha/get-behavior-captcha-token.json?bizType=15"
token = requests.get(token_url).json()['data']
# get captcha image url
captcha_url = "https://passport.youzan.com/api/captcha/get-behavior-captcha-data.json?token={token}&captchaType=1".format(token=token)
big_captcha_url = requests.get(captcha_url).json()['data']['captchaObtainInfoResult']['bigUrl']
filename = str(uuid.uuid4())
urllib.request.urlretrieve(big_captcha_url, "{}/{}.png".format(image_folder,filename))
if __name__=="__main__":
if not os.path.exists(image_folder):
os.mkdir(image_folder)
nums = 100 # how many images?
index = 0
while index <nums:
save_image()
print(index)
index+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment