首页 > 解决方案 > 用于获取网页输出的 powershell 脚本,其中包括用于表单的 javascripts

问题描述

我正在尝试编写一个 powershell 脚本来读取一个使用 javascript 的网页并获取输出。网页源代码如下所示,但浏览器中的页面本身具有由于 javascripts 的形式。我需要通过 powershell 获取表单,但到目前为止还没有成功,因为 Invoke-WebRequest 或 Invoke-RestMethod 只是获取了引用 js 的内容。

<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><meta name=robots content=noindex><link rel=icon href=/websellingbooking/favicon.ico><title>Loading</title><link rel=stylesheet href=/websellingbooking/css/custom.css nonce="nonce-GzB2v2o2sBKmQkE5xM+0cPpjQ+rO8KyK/kI1DdxAQUY=" type=text/css><link href=/websellingbooking/css/app.4975c048.css rel=preload as=style><link href=/websellingbooking/css/bulks-sellerss.67fb10ba.css rel=preload as=style><link href=/websellingbooking/js/app.0c50239a.js rel=preload as=script><link href=/websellingbooking/js/bulks-sellerss.08a611c4.js rel=preload as=script><link href=/websellingbooking/css/bulks-sellerss.67fb10ba.css rel=stylesheet><link href=/websellingbooking/css/app.4975c048.css rel=stylesheet></head><body><div id=app></div><script src=/websellingbooking/js/bulks-sellerss.08a611c4.js></script><script src=/websellingbooking/js/app.0c50239a.js></script></body></html>

标签: javascripthtmlpowershellweb-scraping

解决方案


A) There is no HTML form in the source. If you have control over the websites, it might be an option to write complete HTML pages/templates including the form. That way, all elements are downloadable.

B) The Chromium browser can be used in a headless way, which means without a graphical user interface. Thus one can request a website on a server-environment and get a fully rendered snapshot of the page, as it was loaded in Chromium. See also: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md


推荐阅读