英文:
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链接。
英文:
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.
答案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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论