Method to block image, flash, style when use gecko navigate?

為{幸葍}努か 提交于 2019-12-11 11:59:27

问题


I need to make a bot "get video link" from abc..
I use httpwebrequest and httprespone but I realize this website has ajax text and httpwebsite can't get it.
-> I decide to use geckowebrowser
Step by step
1. use geckowebrowser documentcomplete event and use navigate to website
2. use geckobutton to click and wait 5 seconds to get ajax text
-> It success but too slow, it delay to load style, image, flash, etc

so I try to search and I get this "DOMContentLoaded event fires when the DOM is loaded, but before all page assets are loaded (CSS, images, etc.)." ya, this is what i want, i don't want to load image, flash...
but when i use it, i get this code

    GeckoWebBrowser web2 = new GeckoWebBrowser();
    web2.DOMContentLoaded += Web2_DOMContentLoaded;
    private void Web2_DOMContentLoaded(object sender, DomEventArgs e)
    {
        ...
        //When domcontent loaded i need to get some element
        but i can't find any function can do that here
        i need to use document.getElementById or something like that :(

    }

How can I do that "without global variable" ? or any other "method to block image, css, flash" when use gecko navigate.... please help :(

Thanks for read my post !!


回答1:


Make sure Property of your Gecko Web Browser UseHttpActivityObserver is True.

Now you can handle whether you want to load different types of content or not. Example below is for .jpg. Sorry, it's in VB. To convert it, you can use http://converter.telerik.com/

Private Sub Browser1_ObserveHttpModifyRequest(sender As Object, e As Gecko.GeckoObserveHttpModifyRequestEventArgs) Handles Browser1.ObserveHttpModifyRequest
Dim str = e.Uri.ToString
     If str.Substring(str.Length - 4) = ".jpg" Then
          e.Cancel = True
     End If
End Sub



回答2:


The answer is correct, I only want to point to the same answer in C#

GeckoFX Observer Service



来源:https://stackoverflow.com/questions/32379126/method-to-block-image-flash-style-when-use-gecko-navigate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!