2012-07-09 29 views
0

嘿所有我使用這個代碼在這裏:使用HtmlAgilityPack找到電影鏈接

'WebBrowser1.Navigate("http://0000.org/icampus") 

'Do Until Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete 
' Application.DoEvents() 
'Loop 

'Dim tmpHTML As String = WebBrowser1.Document.Body.InnerHtml 
Dim theWidth As Integer = 500 '1920 
Dim theHeight As Integer = 500 '1080 
Dim doc As New HtmlDocument() 

doc.Load("C:\kathryn\fp.html") 
'doc.LoadHtml(tmpHTML) 

Dim theVidURL As String = doc.DocumentNode.SelectSingleNode("//OBJECT/PARAM[@NAME='Movie']").Attributes("VALUE").Value 

,以便找到電影在這個HTML源的URL:

<DIV id=player-wrapper> 
<DIV id=lcm_video> 
<OBJECT id=player codeBase="http://0000.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 width=480 align=middle height=320 VIEWASTEXT><PARAM NAME="_cx" VALUE="12700"><PARAM NAME="_cy" VALUE="8466"><PARAM NAME="FlashVars" VALUE=""><PARAM NAME="Movie" VALUE="http://0000.lightcastmedia.com/lcplayer_flash112fix.swf?autoStart=1&amp;hidecontrols=1&amp;&amp;noresize=1&amp;file=http%3A%2F%2F%2Fedge2%2F3157%2F070712b&amp;rtmppath=rtmp%3A//chi02.live.lightcastmedia.com%3A1935/mc/_definst_&amp;rtmpfile=fvc/3157/070712b&amp;sec=447"><PARAM NAME="Src" VALUE="http://0000.lightcastmedia.com/lcplayer_flash112fix.swf?autoStart=1&amp;hidecontrols=1&amp;&amp;noresize=1&amp;file=http%3A%2F%2F%2Fedge2%2F3157%2F070712b&amp;rtmppath=rtmp%3A//chi02.live.lightcastmedia.com%3A1935/mc/_definst_&amp;rtmpfile=fvc/3157/070712b&amp;sec=447"><PARAM NAME="WMode" VALUE="Window"><PARAM NAME="Play" VALUE="-1"><PARAM NAME="Loop" VALUE="-1"><PARAM NAME="Quality" VALUE="High"><PARAM NAME="SAlign" VALUE=""><PARAM NAME="Menu" VALUE="-1"><PARAM NAME="Base" VALUE=""><PARAM NAME="AllowScriptAccess" VALUE="sameDomain"><PARAM NAME="Scale" VALUE="ShowAll"><PARAM NAME="DeviceFont" VALUE="0"><PARAM NAME="EmbedMovie" VALUE="0"><PARAM NAME="BGColor" VALUE="000000"><PARAM NAME="SWRemote" VALUE=""><PARAM NAME="MovieData" VALUE=""><PARAM NAME="SeamlessTabbing" VALUE="1"><PARAM NAME="Profile" VALUE="0"><PARAM NAME="ProfileAddress" VALUE=""><PARAM NAME="ProfilePort" VALUE="0"><PARAM NAME="AllowNetworking" VALUE="all"><PARAM NAME="AllowFullScreen" VALUE="true"><PARAM NAME="AllowFullScreenInteractive" VALUE="false"> 

     <embed src="http://0000.lightcastmedia.com/lcplayer_flash112fix.swf?autoStart=1&hidecontrols=1&&noresize=1&file=http%3A%2F%2F%2Fedge2%2F3157%2F070712b&rtmppath=rtmp%3A//chi02.live.lightcastmedia.com%3A1935/mc/_definst_&rtmpfile=fvc/3157/070712b&sec=447" quality="best" FlashVars="" bgcolor="#000000" width="480" height="320" name="player" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> 
    </OBJECT></DIV> 

但由於某些原因我得到一個沒有返回從theVidURL

任何幫助將是偉大的!

UPDATE

我剛剛結束了使用此代碼經過HTML看:

Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("PARAM") 
For Each curElement As HtmlElement In theElementCollection 
    If InStr(curElement.GetAttribute("value"), "lightcastmedia.com") <> 0 Then 
     tmpMovieURL = curElement.GetAttribute("value") 
     Exit For 
    End If 
Next 
+0

運行對我罰款(假設你實際加載與HTML文檔)。你記得這麼做嗎? – 2012-07-09 19:08:45

+0

我打電話給一個HTML頁面,因爲我現在加載的網站沒有現在發佈的電影(他們只在週日打開視頻),但我使用星期日的代碼加載到它來測試使用* * doc.LoadHtml(「C:\ fp.html」)** – StealthRT 2012-07-09 19:10:56

回答

0

我剛剛結束了使用此代碼經過HTML看:

Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("PARAM") 
For Each curElement As HtmlElement In theElementCollection 
    If InStr(curElement.GetAttribute("value"), "lightcastmedia.com") <> 0 Then 
     tmpMovieURL = curElement.GetAttribute("value") 
     Exit For 
    End If 
Next 
1

那麼有你的問題,你加載HTML文件是錯誤的。 LoadHtml()方法用於將包含HTML的字符串解析爲HtmlDocument。如果你想打開一個HTML文件,你可以使用Load()方法。

Dim doc As New HtmlDocument 
doc.Load("C:\kathryn\fp.html") ' load the file 
+0

將其更改爲** doc.Load(「C:\ kathryn \ fp.html」)**仍然會導致** theVidURL **爲** Nothing ** – StealthRT 2012-07-09 19:19:47

+0

用更多的代碼更新了我的OP。 – StealthRT 2012-07-09 19:27:38

+0

那麼你需要在該文件中包含實際的HTML,如果它像你所顯示的那樣,那麼它會起作用。 – 2012-07-09 19:28:45