简体   繁体   中英

How do I follow a Javascript Link without onClick

This is my first time posting. I've been working on a "web scraper" to navigate through a website and download an Excel File or .CSV file automatically.

I'm running into a problem when I want to download the file. Here is the HTML:

<"a class="PSQRYRESULTSTITLE" href="javascript: bSubmitted=false;submitAction_win2(document.win2,'#ICQryDownloadRaw');">CSV Text File<"/a>

When clicked it opens a download prompt to save.

  1. How do I trigger this prompt?
  2. Can I bypass the prompt so it downloads automatically?

I'm coding this in Visual Studio C# 2008. I am using a WebBrowser Control to navigate through the website.

I've tried everything from webbrowser1.document.invokescript to storing all the elements in an HtmlElementCollection traversing through them and doing invokemember("click")...

Nothing is working! Please help!

  1. try invokescript eval with a string parameter of value "javascript: bSubmitted=false;submitAction_win2(document.win2,'#ICQryDownloadRaw');"
  2. you can make an educated guess of the url and use UrlDownloadToFile to download it to your location, or make another web request to download the file if UrlDownloadToFile fails.
foreach (HtmlElement i in webBrowser1.Document.All)
    {
        if (i.OuterText == "CSV Text File" && i.GetAttribute("href") != "")
        {
            webBrowser1.Navigate(i.GetAttribute("href"));
        }
    }

although this doesn't answer my second question of how to automatically download the file or disable the prompt it got me moving forward finally. But if anyone has an answer for that it would be much appreciated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM