【问题标题】:Invoke-webrequest -get request through a custom Chrome profileInvoke-webrequest - 通过自定义 Chrome 配置文件获取请求
【发布时间】:2021-10-17 23:16:34
【问题描述】:

我一直在寻找在打开的自定义 chrome 配置文件上读取 HTML 的方法,但没有成功。

& "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" $url;

我尝试使用 invoke-webrequest,但不知道如何通过自定义配置文件使其工作。

重点是读取是否在 $url 上购买了商品,其中“Profile 1”已登录。

另外,我考虑过使用 POST 方法登录 $url,然后将 HTML 作为变量返回,但我也想不出办法。

【问题讨论】:

    标签: powershell post get webrequest chrome-profile


    【解决方案1】:

    这行不通。这行不通。

    你可以:

    • 在特定配置文件上启动 Chrome
    • 使用Invoke-RestMethod 和/或Invoke-WebRequest

    这两者并不相关。 Powershell cmdlet 的操作不依赖于 Chrome。

    如果你想通过 Chrome 做一些事情,你需要做浏览器自动化。 这是另一回事,需要专门的工具,例如 Selenium。

    您可以直接使用 selenium 的 .Net 接口,也可以使用 Selenium powershell 模块,该模块将帮助您更轻松地与 selenium(以及您选择的浏览器/浏览器配置文件)进行交互。

    安装:

    Install-Module -Name Selenium -AllowPrerelease
    

    请注意,此工具的学习和使用比 Invoke-WebRequest 复杂得多

    参考文献

    Github - Selenium-Powershell

    Powershell Gallery - Selenium

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-21
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 2014-10-10
      • 2023-01-21
      • 1970-01-01
      相关资源
      最近更新 更多