T
T
TechNOIR2017-11-02 15:27:21
PowerShell
TechNOIR, 2017-11-02 15:27:21

Powershell+Selenium. How to bypass the captcha?

Good afternoon.
I wrote a script for parsing information, but on the site the script soon stumbles upon a captcha and crashes.
I already found how to send a picture. Through a third party API.
BUT! The link to the captcha image looks like this:

http://www.site.ru/captcha.ashx?guid=d7s8f7sdf9sd798f

How to get this picture? There is an idea, of course, to take a screenshot, then in this case, how to take a screenshot of a specific object (captcha)? For example, you can select somehow with the help of Selenium and take a screenshot from the area.
Any ideas, fellow experts? thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2017-11-02
@dimonchik2013

from selenium import webdriver
from PIL import Image

fox = webdriver.Firefox()
fox.get('http://toster.ru/')

# now that we have the preliminary stuff out of the way time to get that image :D
element = fox.find_element_by_id('hlogo') # find part of the page you want image of
location = element.location
size = element.size
fox.save_screenshot('screenshot.png') # saves screenshot of entire page
fox.quit()

im = Image.open('screenshot.png') # uses PIL library to open image in memory

left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height']


im = im.crop((left, top, right, bottom)) # defines crop points
im.save('screenshot.png') # saves new cropped image

sometimes you need to scroll to the end of the page, then it's a little more difficult

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question