最近在练习 验证码辨识
想说试试看自己测试其他网站能不能成功
结果光是下载验证码图片就困扰我一阵子啦
同样的code
在gztown就抓得到
https://pt.gztown.net/login.php
但是在学校网站却抓不到
https://www.ais.tku.edu.tw/EleCos/login.aspx
想请教该如何解决?
code如下(从#1QFyrfBX (Python)改写的):
import shutil
import requests
import time
from bs4 import BeautifulSoup
SAVEPATH = "./data/manual_label/"
url = "https://pt.gztown.net/login.php"
#url = 'http://railway1.hinet.net/ImageOut.jsp'
for i in range(1, 3000):
#先抓出验证码图片的网址 img_url
r = requests.get(url, stream = True)
soup = BeautifulSoup(r.text, 'html.parser')
img = soup.find_all('img')
src = img[1].get('src')
img_url = "https://pt.gztown.net/" + src
response = requests.get(img_url, stream=True)
with open(SAVEPATH + str(i) + '.jpg', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
time.sleep(0.1)
谢谢各位前辈