apex1
Regular Member
- May 29, 2015
- 217
- 182
I'm trying to scrape the captcha image and sent it to the 2Captcha API
What the code below does:
The problem is the bot is supposed to be solving captchas on website pages.
Take Pingler for example:
I would need to pull that image directly off the page without doing the whole process I did above because when I visit the scraped URL it reloads a new captcha.
Code looks like this, they're hiding the image location:
What would you experienced guys do to solve this problem?
What the code below does:
- Scrapes source code from pingler
- Identifies and scrapes a URL with "api-secure.mediasolve" in it (captcha load URL)
- Disables javascript and opens browser
- Visits the captcha page (only loads when JS is disabled)
- Takes a screenshot
- Crops the image
- Saves the image
Code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
import urllib.request
import re
from PIL import Image
scrape = urllib.request.urlopen('https://pingler.com').read()
soup = BeautifulSoup(scrape, 'html.parser')
for elem in soup.find_all('iframe', src=re.compile('https://api-secure\.solvemedia\.com')):
nav = (elem['src'])
chrome_options = Options()
chrome_options.add_experimental_option( "prefs",{'profile.managed_default_content_settings.javascript': 2})
nojs_driver = webdriver.Chrome("C:\\Program Files (X86)\\Google\\chromedriver.exe",chrome_options=chrome_options)
nojs_driver.get(nav)
nojs_driver.implicitly_wait(10)
nojs_driver.get_screenshot_as_file('1.png')
img = Image.open("1.png")
img2 = img.crop((0, 0, 350, 200))
img2.save("2.png")
The problem is the bot is supposed to be solving captchas on website pages.
Take Pingler for example:
I would need to pull that image directly off the page without doing the whole process I did above because when I visit the scraped URL it reloads a new captcha.
Code looks like this, they're hiding the image location:
What would you experienced guys do to solve this problem?