Baidu cut button map
First Save FIG down the entire window
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
element = driver.find_element_by_xpath('//input[@id="su"]')
# 坐标
print(element.location)
# 大小
print(element.size)
# 把当前窗口截图保存
driver.get_screenshot_as_file('1.png')
Under normal circumstances, directly based on the coordinates and size of the image, parameters corresponding to Crop Allows you to ()
from PIL import Image
image = Image.open('1.png')
x = 738
y = 220
im = image.crop((x, y, x + 100, y + 36))
im.show()
The result is this?
Look this content, just cut to the "degree" word, there is such a long distance to the target length
The reason is that scaling and layout of your computer (desktop, right, display settings) with 125% of the recommended settings
This setting can be transferred back to one hundred percent accurate shots
Crop Allows you to or at the time of () parameter, multiplied by the ratio corresponding to all the columns can be accurately screenshot
from PIL import Image
image = Image.open('1.png')
x = 738 * 1.25
y = 220 * 1.25
im = image.crop((x, y, x + 100 * 1.25, y + 36 * 1.25))
im.show()