Upload captcha image using Scrapy Request

I am trying to solve a problem using 2Captcha.com. First, I save the captcha image:

urllib.urlretrieve(captcha_image_link, 'captcha.jpg')

Next, I need to upload the image to the server to find out. Using simple queries is as simple as

files = {'file': open('captcha.jpg', 'rb')}
payload = {'key': TWOCAPTCHA_APIKEY, 'method': 'post'}
request = requests.post('http://2captcha.com/in.php', files=files, data=payload)

But how to make the same request using Scrapy? I mean, how to connect the image file to the POST request? Is it possible? If not, then I would like to know if it is too bad idea to use a simple POST request (as well as urlretrieve) inside a Scrapy spider or not?

+4
source share
1 answer

POST Scrapy (. ), , :

  • , requests.post .
  • Scrapy , , , , , captcha.

, aproach Scrapy spider.

0

Source: https://habr.com/ru/post/1683618/


All Articles