'How do I get the pixel coordinates of a multi layered picture using the pillow lib?
I'm using selenium to scrape tiktok data but now tiktok has put a specific form of Captcha to weed out bot activity. I'm trying to solve this captcha but it is presenting a challenge because the image is a multi-layered image that requires a javascript generated png image to be placed on top of the original image via a scroll element.
screenshot
as you can see from the screenshot. the image is multi-layered. I've been using the PIL.image library to get the pixels. the pixels coordinates that I'm looking for, are the ones where the Javascript image is placed so I can scroll and place the image through selenium. is it possible to achieve this and if so can someone help me, here is my code.
from lib2to3.pgen2 import driver
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import *
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.alert import Alert
from webdriver_manager.opera import OperaDriverManager
from PIL import Image
import urllib.request
driver = webdriver.Opera(executable_path=OperaDriverManager().install())
video_list = []
url = "https://www.tiktok.com/@nkosazana_daughter"
driver.get(url)
try:
driver.implicitly_wait(30)
popup = driver.find_element(By.XPATH,'.//*[@id="tiktok-verify-ele"]/div')
if popup is False:
driver.quit()
elif popup is not None:
popup_pic = driver.find_element(By.XPATH, './/*[@id="captcha-verify-image"]')
except Exception as e:
print(e)
finally:
pic = popup_pic.get_attribute('src')
urllib.request.urlretrieve(pic, 'pic.png')
img = Image.open('pic.png')
print(img.getpixel(xy=(0,5)))
print(img.getbbox())
print(img.getbands())
print(img.getdata(0))
pic2 = popup.get_attribute('alt src')
print(pic2)
output
(88, 102, 49)
(0, 0, 552, 344)
('R', 'G', 'B')
<ImagingCore object at 0x0000025C45276AF0>
None
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
