2
확인 이미지를 크롤링하고 싶습니다. 이처럼 컬을 사용하여 달성했습니다.Python 크롤러 확인 그림
curl "https://www.ris.gov.tw/apply/captcha/image?CAPTCHA_KEY=71cc3b094e824446873038401ab8c303&time=1464968502855" -H "Referer: https://www.ris.gov.tw/id_card/" --insecure >> a.jpg
P.S (마다 생성되는 CAPTCHA_KEY
및 time
필요)
그것은 잘 작동하고 a.jpg
로 검증 사진을 저장.
이제 파이썬으로 다시 작성하려고했는데, 여기에 내가 한 일이 있습니다.
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import shutil
import time
from IPython.display import Image
from random import randint
ori = requests.get("https://www.ris.gov.tw/id_card/")
soup = BeautifulSoup(ori.text)
key = soup.select('#captchaKey')[0]["value"]
#Get CAPTCHA_KEY
rs = requests.session()
url = "https://www.ris.gov.tw/apply/captcha/image?CAPTCHA_KEY=" + key
time = str(int((time.time())*100)) + str(randint(0,9))
url += "&time=" + time
#Get time
res = rs.get(url, headers={'referer': 'https://www.ris.gov.tw/id_card/'}, stream = True, verify =False)
f= open('check.jpg','wb')
shutil.copyfileobj(res.raw,f)
f.close()
Image('check.jpg')
나는 잠시 붙어서 어떻게 알아 내야할지 몰랐다.
res = rs.get(url, headers={'referer': 'https://www.ris.gov.tw/id_card/'})
with open('check.jpg', 'wb') as jpeg_file:
jpeg_file.write(res.content)
content 파일에 직접 기록 할 수있는 바이트와 같은 응답은 다음과 같습니다
그래서 오류가 발생 했습니까? – Kevin
확인 이미지를 얻지 못했고'check.jpg '이 그림 형식이 아닌 것 같습니다. 열 수 없습니다. –
무엇이 잘못되었는지 찾아내는 데 도움이 필요하면 [mcve] –