python如何截长图

网上查到有个第3方接口(网页截屏大师)可以实现截取网页长图,只能针对部分网站调用

首先,先在https://www.screenshotmaster.com/ 注册一个账号,在用户中心获取到一个唯一的Token,并保存

然后使用Python脚本调用截屏大师的接口获取截图,代码示例:

import urllib.parse
import urllib.request
import ssl

ssl._create_default_https_context = ssl._create_unverified_context

# 参数
token = "62ea1704908d6"
url = urllib.parse.quote_plus("https://www.baidu.com")
width = 1280
height = 800
full_page = 1

# 构造URL
query = "https://www.screenshotmaster.com/api/v1/screenshot"
query += "?token=%s&url=%s&width=%d&height=%d&full_page=%s" % (token, url, width, height, full_page)

# 调用API
urllib.request.urlretrieve(query, "./screenshot.png")

 

posted @ 2022-09-02 18:54  沐小木  Views(128)  Comments(0Edit  收藏  举报