Created
October 25, 2020 11:45
-
-
Save jerryan999/cf76df79543b675b781f4ba2c0d4d378 to your computer and use it in GitHub Desktop.
download captcha image for training study
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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