首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取网站源码为字符串

获取网站源码为字符串
EN

Stack Overflow用户
提问于 2016-07-18 03:58:39
回答 1查看 947关注 0票数 1

我不知道如何用GeckoFX将网站的源代码放到一个字符串中。

当我使用

代码语言:javascript
复制
GeckoWebBrowser1.ViewSource("www.google.de")

一个新的窗口将打开,里面有源代码,很高兴看到,但没有机会将其加载到字符串中。

当我使用

代码语言:javascript
复制
GeckoWebBrowser1.Navigate("view-source:www.google.de")

源代码显示在GeckoFX浏览器中,但我也不知道如何将其转换为字符串。

我确信解决方案很简单,但我看不出来。因此,如果有人能帮助我摆脱这场斗争,那就太好了。

EN

回答 1

Stack Overflow用户

发布于 2016-07-18 07:56:48

每个人都有很多方法来检索网站的html。如前所述,您可以使用WebClient类来检索它,或者在本例中使用GeckoFX。为了获得内部html,您需要先研究DocumentElement,然后再研究GeckoHtmlElement……

代码语言:javascript
复制
 Dim element As GeckoHtmlElement = Nothing
 Dim geckoDomElement = GeckoWebBrowser1.Document.DocumentElement
 If TypeOf geckoDomElement Is GeckoHtmlElement Then
    element = DirectCast(geckoDomElement, GeckoHtmlElement)
    If element IsNot Nothing AndAlso element.InnerHtml IsNot Nothing Then
      Dim innerHtml = element.InnerHtml 'this is the source of the webpage. Here do what you want with the html...          
    End If
 End If
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38425412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档