vb.net从webbrowser获取值到文本框

时间:2015-04-24 14:37:09

标签: vb.net textbox getattribute

我正在尝试编写一个代码来从某个网站下载一部电影,而我却一直试图将这个值放到文本框中,但是这段代码的其余部分已经完成了,所以我想,没有别的问题。所以这是来自网站的代码:`

        <div style="width:750px;z-index: 0;background:#000;color:#FFF;text-align:center">
                <div class="embed">
                            <div style="height:429px;width:750px;z-index:0;position:relative;clear:both">
                <span id="206019b3744f78869b9bd120161c7b25"><object width="100%" height="100%" id="206019b3744f78869b9bd120161c7b25_api" name="206019b3744f78869b9bd120161c7b25_api" data="http://premium.iitv.info/static/player/flowplayer.commercial-3.2.15.swf" type="application/x-shockwave-flash"><param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always"><param name="quality" value="high"><param name="bgcolor" value="#000000"><param name="flashvars" value="config={&quot;key&quot;:&quot;#$3f90d28e7547ada6c98&quot;,&quot;clip&quot;:{&quot;url&quot;:&quot;http://stream.streamo.tv/?scode=w0GCOWxpkyGA4MJoRu2ETWHHZI3ZEIHojZHZPERJI9PIO90YyE0XMEQF3qUBQA1nkERocWaLaWxEipGn4cHGuuRIH9FnaM3p3fzZHq0oxyHBOERo5AGJvSKoUuHok80X4IwoIq3FhuJBe1RI5AJp30zE4MKpYS0DRAGoKczo5VmIPkTMSIzovWRpvOmE1pwM3gTo65JrlDILSyzFGMHIGWyG1c2G3pzJcEKIX9TJ0NQrSWGp1jxF4IUqeg2nepaqL5RG2cRr55zAaIKIYIKIEWwpCWJHnqmLzA1Z19RqeZmZJcUMeymoeDJGQg2pvkJq3NaZ1x2LzqyIVWyH5f2pLgTMCyIHMW1XcSzDREIGlqyDd50LIyIpbyHL1HyIUImEwuTrGAxnbuxD192Y61HLnSyHL9HBxyUokkHJj92LUSyEFMxAi1xnP1TqGWRrnSUB0N3H1W2ZTATGZyJBcWTrvIxq2LKnf9TnjSJnjtKoUy1E6WaoiZTIT52HjWSZh9RFxMJJaAmEcSKF&quot;,&quot;provider&quot;:&quot;lighttpd&quot;,&quot;scaling&quot;:&quot;fit&quot;,&quot;backgroundGradient&quot;:&quot;none&quot;,&quot;autoPlay&quot;:false,&quot;autoBuffering&quot;:false},&quot;canvas&quot;:{&quot;backgroundColor&quot;:&quot;#000&quot;,&quot;backgroundGradient&quot;:&quot;none&quot;},&quot;plugins&quot;:{&quot;lighttpd&quot;:{&quot;url&quot;:&quot;flowplayer.pseudostreaming-3.2.11.swf&quot;,&quot;queryString&quot;:&quot;%3Fstart%3D%24%7Bstart%7D&quot;},&quot;controls&quot;:{&quot;url&quot;:&quot;flowplayer.controls-3.2.14.swf&quot;,&quot;autoHide&quot;:&quot;always&quot;}},&quot;playerId&quot;:&quot;206019b3744f78869b9bd120161c7b25&quot;,&quot;playlist&quot;:[{&quot;url&quot;:&quot;http://stream.streamo.tv/?scode=w0GCOWxpkyGA4MJoRu2ETWHHZI3ZEIHojZHZPERJI9PIO90YyE0XMEQF3qUBQA1nkERocWaLaWxEipGn4cHGuuRIH9FnaM3p3fzZHq0oxyHBOERo5AGJvSKoUuHok80X4IwoIq3FhuJBe1RI5AJp30zE4MKpYS0DRAGoKczo5VmIPkTMSIzovWRpvOmE1pwM3gTo65JrlDILSyzFGMHIGWyG1c2G3pzJcEKIX9TJ0NQrSWGp1jxF4IUqeg2nepaqL5RG2cRr55zAaIKIYIKIEWwpCWJHnqmLzA1Z19RqeZmZJcUMeymoeDJGQg2pvkJq3NaZ1x2LzqyIVWyH5f2pLgTMCyIHMW1XcSzDREIGlqyDd50LIyIpbyHL1HyIUImEwuTrGAxnbuxD192Y61HLnSyHL9HBxyUokkHJj92LUSyEFMxAi1xnP1TqGWRrnSUB0N3H1W2ZTATGZyJBcWTrvIxq2LKnf9TnjSJnjtKoUy1E6WaoiZTIT52HjWSZh9RFxMJJaAmEcSKF&quot;,&quot;provider&quot;:&quot;lighttpd&quot;,&quot;scaling&quot;:&quot;fit&quot;,&quot;backgroundGradient&quot;:&quot;none&quot;,&quot;autoPlay&quot;:false,&quot;autoBuffering&quot;:false}]}"></object></span>`

我希望得到这个:

<param name="flashvars" value="config={&quot;key&quot;:&quot;#$3f90d28e7547ada6c98&quot;,&quot;clip&quot;:{&quot;url&quot;:&quot;http://stream.streamo.tv/?scode=w0GCOWxpkyGA4MJoRu2ETWHHZI3ZEIHojZHZPERJI9PIO90YyE0XMEQF3qUBQA1nkERocWaLaWxEipGn4cHGuuRIH9FnaM3p3fzZHq0oxyHBOERo5AGJvSKoUuHok80X4IwoIq3FhuJBe1RI5AJp30zE4MKpYS0DRAGoKczo5VmIPkTMSIzovWRpvOmE1pwM3gTo65JrlDILSyzFGMHIGWyG1c2G3pzJcEKIX9TJ0NQrSWGp1jxF4IUqeg2nepaqL5RG2cRr55zAaIKIYIKIEWwpCWJHnqmLzA1Z19RqeZmZJcUMeymoeDJGQg2pvkJq3NaZ1x2LzqyIVWyH5f2pLgTMCyIHMW1XcSzDREIGlqyDd50LIyIpbyHL1HyIUImEwuTrGAxnbuxD192Y61HLnSyHL9HBxyUokkHJj92LUSyEFMxAi1xnP1TqGWRrnSUB0N3H1W2ZTATGZyJBcWTrvIxq2LKnf9TnjSJnjtKoUy1E6WaoiZTIT52HjWSZh9RFxMJJaAmEcSKF&quot;,&quot;provider&quot;:&quot;lighttpd&quot;,&quot;scaling&quot;:&quot;fit&quot;,&quot;backgroundGradient&quot;:&quot;none&quot;,&quot;autoPlay&quot;:false,&quot;autoBuffering&quot;:false},&quot;canvas&quot;:{&quot;backgroundColor&quot;:&quot;#000&quot;,&quot;backgroundGradient&quot;:&quot;none&quot;},&quot;plugins&quot;:{&quot;lighttpd&quot;:{&quot;url&quot;:&quot;flowplayer.pseudostreaming-3.2.11.swf&quot;,&quot;queryString&quot;:&quot;%3Fstart%3D%24%7Bstart%7D&quot;},&quot;controls&quot;:{&quot;url&quot;:&quot;flowplayer.controls-3.2.14.swf&quot;,&quot;autoHide&quot;:&quot;always&quot;}},&quot;playerId&quot;:&quot;206019b3744f78869b9bd120161c7b25&quot;,&quot;playlist&quot;:[{&quot;url&quot;:&quot;http://stream.streamo.tv/?scode=w0GCOWxpkyGA4MJoRu2ETWHHZI3ZEIHojZHZPERJI9PIO90YyE0XMEQF3qUBQA1nkERocWaLaWxEipGn4cHGuuRIH9FnaM3p3fzZHq0oxyHBOERo5AGJvSKoUuHok80X4IwoIq3FhuJBe1RI5AJp30zE4MKpYS0DRAGoKczo5VmIPkTMSIzovWRpvOmE1pwM3gTo65JrlDILSyzFGMHIGWyG1c2G3pzJcEKIX9TJ0NQrSWGp1jxF4IUqeg2nepaqL5RG2cRr55zAaIKIYIKIEWwpCWJHnqmLzA1Z19RqeZmZJcUMeymoeDJGQg2pvkJq3NaZ1x2LzqyIVWyH5f2pLgTMCyIHMW1XcSzDREIGlqyDd50LIyIpbyHL1HyIUImEwuTrGAxnbuxD192Y61HLnSyHL9HBxyUokkHJj92LUSyEFMxAi1xnP1TqGWRrnSUB0N3H1W2ZTATGZyJBcWTrvIxq2LKnf9TnjSJnjtKoUy1E6WaoiZTIT52HjWSZh9RFxMJJaAmEcSKF&quot;,&quot;provider&quot;:&quot;lighttpd&quot;,&quot;scaling&quot;:&quot;fit&quot;,&quot;backgroundGradient&quot;:&quot;none&quot;,&quot;autoPlay&quot;:false,&quot;autoBuffering&quot;:false}]}">

如果这是必要的话,它可能是完整的4行。

我一直在寻找最近5个小时的解决方案,我找不到任何有用的东西......

2 个答案:

答案 0 :(得分:1)

快速而肮脏的方法是:

1)使用以下代码将网页的HTML内容下载到字符串中:

Dim htmlContent As String = New System.Net.WebClient().DownloadString(<Enter URL Here>)

2)...然后在字符串中搜索您的代码。一种方法是先在HTML中的哪个位置找到字符串&#34; http://stream.streamo.tv/?scode=&#34;位于......

Dim codeLocation As Integer = htmlContent.IndexOf("http://stream.streamo.tv/?scode=")

然后浏览每个后续角色,逐个角色地构建代码,直到找到终止角色(例如&#34;&amp;&#34;)。

我假设此代码仅在页面上出现一次。如果没有,您将需要找到一种循环每个实例的方法(这并不困难,但这里没有涉及)。

答案 1 :(得分:0)

也许它会起作用,但它是html代码的动态部分,因此页面源中没有链接,只有选择“inspect element”函数才能找到它...

我试图做这样的事情,但我找不到工作解决方案......:

1

如果我这样做:

For Each h As HtmlElement In WebBrowser1.Document.GetElementsByTagName("value")
If Not Object.ReferenceEquals(h.GetAttribute("name"), Nothing) AndAlso h.GetAttribute("name").Equals("flashvars") Then
Tbox1.Text = h.InnerText
Exit For
End If
Next

然后我可以在这里设置数据:

(...).SetAttribute("Value", TextBox4.Text)

但我不知道如何扭转这种情况并将其转换为文本框:

<param name="flashvars" value="here"></param>