简体   繁体   English

如何在没有onClick的情况下遵循Javascript链接

[英]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. 我一直在研究“网页抓取工具”,以浏览网站并自动下载Excel文件或.CSV文件。

I'm running into a problem when I want to download the file. 我要下载文件时遇到问题。 Here is the HTML: 这是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. 我在Visual Studio C#2008中对此进行编码。我正在使用WebBrowser控件浏览网站。

I've tried everything from webbrowser1.document.invokescript to storing all the elements in an HtmlElementCollection traversing through them and doing invokemember("click")... 我尝试了所有内容,从webbrowser1.document.invokescript到将所有元素存储在遍历它们并执行invokemember(“ click”)的HtmlElementCollection中...

Nothing is working! 什么都没用! Please help! 请帮忙!

  1. try invokescript eval with a string parameter of value "javascript: bSubmitted=false;submitAction_win2(document.win2,'#ICQryDownloadRaw');" 尝试使用字符串参数值"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. 您可以对URL进行有根据的猜测,并使用UrlDownloadToFile将其下载到您的位置;如果UrlDownloadToFile失败,则可以提出另一个Web请求以下载文件。
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. 但是,如果有人对此有答案,将不胜感激。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将我的onclick事件链接到外部javascript函数? - How do I link my onclick event to an external javascript function? 如何将“ onClick”事件链接到javascript文件? - How do I link an “onClick” event to a javascript file? 如何触发与AUI链接的onclick javascript? - How do I trigger a onclick javascript of a link with AUI? 如何在没有onclick事件的情况下使用javascript更改图片? - How do I change an image with javascript without an onclick event? 使用javascript onclick时,我在IE中显示一个小链接图标,如何删除它? - When using javascript onclick I'm getting a small link icon in IE, how do I remove this? 如何在不单击链接的情况下出现JavaScript弹出窗口? - How do I get a JavaScript popup to come without clicking link? 如何在 Javascript 中不显示 URL 的情况下创建链接? - How do I create a link without the URL being visible in Javascript? 如何在新选项卡中打开div链接Javascript onClick =“window.location - How do I make a div link open in a new tab Javascript onClick="window.location 如何使用JQuery在HTML中创建带有quote-includes-string参数的onclick javascript链接? - How do I use JQuery to create an onclick javascript link in HTML with quote-including-string parameters? 如何使用javascript / jquery添加到页面链接(url)的OnClick函数 - How do I add OnClick function that goes to a page link (url) with javascript/jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM