ASP.NET Core + Selenium 实现 网页截图 以及 获取网页源代码 等
ASP.NET Core + Selenium 实现 网页截图 以及 获取网页源代码 等
-
https://webscreenshot.onrender.com/?url=https://blog.imlete.cn
-
https://webscreenshot.onrender.com/?url=https://blog.imlete.cn&windowWidth=1280
- 浏览器窗口宽 1280, 高度自动延展
-
- 注入 js, 修改页面
-
https://webscreenshot.onrender.com/?url=https://www.google.com
-
- 强制等待 20 秒
-
https://webscreenshot.onrender.com/?url=https://xiaokang.me&mode=html
- 使用 mode=html 获取网页源代码
-
- 指定区域截图
%20
为空格 UrlEncode 后
-
- 指定区域获取网页源代码
%20
为空格 UrlEncode 后
注意:
若需获取JavaScript
执行后的网页源代码, 你可能需要forceWait
,
并且尽量使用cssSelector
, 例如cssSelector=body
- 点击下方按钮 一键部署
- 免费注册, 无需信用卡验证
- Free Instance Hours: 750 hours/month
- Free Bandwidth: 100 GB/month
- Free Build Minutes: 500 min/month
- 注意 : 免费实例类型上的 Web 服务在闲置 15 分钟后会自动停止运行, 当一个新的免费服务请求进来时, Render 会再次启动它, 以便它可以处理该请求, 因此为了保证存活, 请使用第三方监控保活, 例如: UptimeRobot: 免费网站监控服务
- 点击下方按钮 一键部署
- 免费注册, 无需信用卡验证
- 每月
$5.00
免费额度 / 每月 500 小时免费执行时间- 无需保活, 在免费额度用完之前永不停止运行
- 点击下方按钮 一键部署
- 注意 : Heroku 应用一段时间不访问会自动休眠, 因此为了保证存活, 请使用第三方监控保活, 例如: UptimeRobot: 免费网站监控服务
# 获取源代码: 方式1: ssh
git clone [email protected]:yiyungent/WebScreenshot.git
# 获取源代码: 方式2: https
git clone https://github.com/yiyungent/WebScreenshot.git
docker build -t yiyungent/webscreenshot -f src/WebScreenshot/Dockerfile .
docker run -d -p 5004:80 -e ASPNETCORE_URLS="http://*:80" --name webscreenshot yiyungent/webscreenshot
环境变量名称 | 必填 | 备注 |
---|---|---|
WEBSCREENSHOT_CACHEMINUTES |
截图 缓存时间 (分钟), 默认 60 | |
WEBSCREENSHOT_CACHEMODE |
缓存模式, 默认 memory, 可填 file | |
WEBSCREENSHOT_DEBUG |
是否开启 debug, 默认 false, 开启则 true, 开启后当出现异常时会在页面显示异常信息 |
注意:
强烈建议 使用
Railway
部署的用户,设置WEBSCREENSHOT_CACHEMODE
为file
, 降低内存占用,大多数
出错啦!
,都是由于内存不足
注意:
Railway
Deploy
, 处于ACTIVE
后,此时Server Error
,只需要等待一会完全启动完成即可。
注意:
正常运行较长时间后, 当
Railway
长时间 显示Server Error
时,但Railway
后台处于active
时,说明 服务已经挂掉,你可以通过 修改 环境变量 (无需真修改,只要点击 √ 保存一次就行) 的方式,重新触发
Deploy
WebScreenshot is an MIT licensed open source project and completely free to use. However, the amount of effort needed to maintain and develop new features for the project is not sustainable without proper financial backing.
We accept donations through these channels:
WebScreenshot © yiyun, Released under the MIT License.
Authored and maintained by yiyun with help from contributors (list).
GitHub @yiyungent Gitee @yiyungent