获取在浏览器中显示的 HTML 代码的程序化方法是什么?

huangapple go评论65阅读模式
英文:

How can I get html code that is shown in a browser programmatically?

问题

使用.NET,我如何以编程方式获取在浏览器中显示的HTML代码(并可以通过Chrome或Opera的“另存为”命令保存的代码)?

使用HtmlDocument.Load()wget无济于事 - 我将得不到我想要的。

请参阅此处的讨论

编辑

不幸的是,.Net WebClient(或者是新的.Net.Http.HttpClient)类并没有帮助(请参阅bdcoder的答案)。我得到了与HtmlDocument.Load()wget相同的结果。不是浏览器保存的HTML代码。

let myHtml =         
    async 
        {     
            let client = new System.Net.Http.HttpClient()
            let! responseBody = 
                client.GetStringAsync("https://www.kodis.cz/lines/region?tab=232-293")
                |> Async.AwaitTask
            return responseBody
        } |> Async.RunSynchronously
英文:

Using .NET, how can I get the html code that is shown in a browser (and that can be saved from browsers such as Chrome or Opera through Save As commands) programmatically?

Using HtmlDocument.Load() or wget is to no avail - I will not get what I want.

See also the discussion here.

EDIT

Unfortunatelly the .Net WebClient (or rather the new .Net.Http.HttpClient) class did not help (see the answer by bdcoder). I got the same result as with HtmlDocument.Load() or wget. Not the html code that the browsers save.

let myHtml =         
    async 
        {     
            let client = new System.Net.Http.HttpClient()
            let! responseBody = 
                client.GetStringAsync("https://www.kodis.cz/lines/region?tab=232-293")
                |> Async.AwaitTask
            return responseBody
        } |> Async.RunSynchronously

答案1

得分: 1

如果您查看浏览器开发工具的网络面板,您可以看到JavaScript正在调用以获取PDF数据的终端点。您可以使用HttpClient来请求相同的数据,然后解析JSON以获取PDF链接。

获取在浏览器中显示的 HTML 代码的程序化方法是什么?

英文:

If you look in the network panel of the browser dev tools you can see the endpoint the JavaScript is calling to get the PDF data. You can use the HttpClient to request the same data then parse the JSON to get the pdf links.

获取在浏览器中显示的 HTML 代码的程序化方法是什么?

答案2

得分: 0

你试过使用 .Net WebClient 类吗?你应该能够从任何 URL 获取页面,保存结果,然后相应地处理 HTML 代码。

希望有所帮助。

英文:

Have you tried the .Net WebClient class? You should be able to fetch a page from any URL, save the result and then process the HTML code accordingly.

Hope that helps.

答案3

得分: 0

Another potential solution to my problem is suggested here (an answer by Tomáš Petříček).

英文:

Another potential solution to my problem is suggested here (an answer by Tomáš Petříček).

huangapple
  • 本文由 发表于 2023年4月4日 09:10:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924785.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定