简体   繁体   中英

C# using hidden webbrowser control to get content of page

Hy,

I'm using the webbrowser control to get some content of a page and use that in the program (C#).

When I've got the webbrowser visible (this.webBrowser1.Visible = true;) the program just runs fine, but when i set the value to false (this.webBrowser1.Visible = false;), I get errors on this part of code:

HtmlWindow SContentFrame = webBrowser1.Document.Window.Frames[1];
HtmlWindow Frame_A = SContentFrame.Document.Window.Frames[2];
HtmlElementCollection bigFontTags = Frame_A.Document.GetElementsByTagName("b");

Do I need to select the webbrowser or something like that??? or is there an another problem? Because when the webbrowser controller is visible, this piece of code works, but when I hide the webbrowser, it doesn't work at all...

Any thoughts would be appreciated....

TWCrap

Sounds like you are approaching this the wrong way.

The webbrowser is not meant to be used in this way, why not just download the contents of the webpage in the background using WebClient for example? This has a much lower overhead than the WebBrowser.

The HTML Agility Pack is very useful if you are working on a scraping type application.

一个简单的技巧是隐藏表单上的浏览器偏移量,因此,例如,如果表单的宽度为300 px,则将浏览器的左侧放置在350上

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