从用户webBrowser获取最新的pastebin .txt c#

问题描述 投票:0回答:1

我从服务器更新的用户使用Pastebin。我需要定期更新我的自定义服务器。因此,我需要他的Pastebin中最新的.txt。我想自动获取最新的链接。因此,我的服务更新程序可以读取它。我在visual studio c#中使用Windows Forms。

尝试从html页面获取ID,但无法从他的pastebin获取最新的.text。

webBrowser1.Navigate("https://pastebin.com/u/xxxxx");
webBrowser1.Document.GetElementById(latestandgreatest).InvokeMember("Click");
url = webBrowser1.Url.AbsoluteUri; 
NewestUpdateLink = url;

显然“lastestandgreatest”有些如何表示用户发布的最新.txt文件的链接...

任何想法......先谢谢!

c# html winforms webbrowser-control pastebin
1个回答
0
投票

导航到网站后,您无法立即下载该文件。以表单加载方式导航到网站

    private void Form2_Load(object sender, EventArgs e)
    {
        webBrowser1.Navigate("https://pastebin.com/jFhS1daA");
        webBrowser1.ScriptErrorsSuppressed = true;
    }

在Web浏览器文档中完成操作,找到您要下载的链接并调用click事件

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        // Find the download link by text
        HtmlElement htmlElement = (from HtmlElement element in webBrowser1.Document.GetElementsByTagName("A") select element)
            .Where(x => string.Compare(x.InnerText, "download", true) == 0).FirstOrDefault();
        if (htmlElement != null)
        {
            htmlElement.InvokeMember("click");
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.