Источник страницы с кодом:
Код: Выделить всё
Для просмотра статьи разгадайте капчу
для просмотра статьи разгадайте капчу
[img]/captcha/securimage_show.php[/img]
[url=#][ показать другую картинку ][/url]
Что-то вроде:
Код: Выделить всё
import requests
from PIL import Image
import io
pdf_url = "http://moscow.sci-hub.io/3dcd1bf3b82ea549c0a72e9ab195ab78/walter2015.pdf"
r1 = requests.get(pdf_url)
if r1.headers['Content-Type'] != 'application/pdf':
print("Looks like Sci-hub gave us a captcha")
image = requests.get("http://moscow.sci-hub.io/captcha/securimage_show.php").content
img = io.BytesIO(image)
im = Image.open(img)
im.show()
captcha_text = input("Enter captcha text: ")
r2 = requests.post(pdf_url, data = {'captcha_code': captcha_text})
if r2.headers['Content-Type'] != 'application/pdf':
print("Looks like Sci-hub gave us another captcha")
else:
with open("filename.pdf", 'wb') as f:
f.write(r.content)
print("saved!")
else:
print("Got a PDF")
with open("filename.pdf", 'wb') as f:
f.write(r.content)
print("saved!")
Подробнее здесь: https://stackoverflow.com/questions/433 ... irect-link