开发者

Copy all text from webbrowser control

开发者 https://www.devze.com 2022-12-27 01:14 出处:网络
Is it possible to scrape all the tex开发者_运维技巧t from a site that was navigated to by WebBrowser control without looking at the source?David Walker\'s method is great when one don\'t need any info

Is it possible to scrape all the tex开发者_运维技巧t from a site that was navigated to by WebBrowser control without looking at the source?


David Walker's method is great when one don't need any info from the header nor non main part of the webpage. if one need something outside inner text, there is only two options, one is to parse with "getElement". the other one is issue commands (Document.ExecCommand) to webbrowser to select all and copy to clipboard:

wb.Document.ExecCommand("SelectAll", false, null);
wb.Document.ExecCommand("Copy", false, null);

then finally string content=clipboard.getText();

Please note the spelling and syntax may not be correct, I'm recalling from my memory


string browserContents = webBrowser.Document.Body.InnerText;


You use the DocumentText property or the WebBrowser control.

This property is what holds the HTML of the site you have navigated to.

Update: (following comments)

If you want to parse the HTML and get the text parts of it, I suggest you use the HTML Agility Pack.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号