开发者

Defining a variable as a url in a page source using VB.net?

Im writing a program in VB.net that consists of three main steps:

STEP 1: Display the source code of a webpage that is streaming a movie on it in textbox1.

STEP 2: highlight the URL to that movie in the source code, and then display just the URL in textbox3.

STEP开发者_JAVA技巧 3: Download that movie using HttpWebRequest and HttpWebResponse to a user defined directory

The problem is that i dont know how i would go about extracting the URL from the source code effectively. maybe i could try searching the source code for the string ".mp4" or ".avi" or other video extensions, but that would only find the end of the link, how would i highlight the whole link?

For example: if i searched the source code for ".mp4" and there was a URL such as

"http://megavideo.com/g7987bfd0fg.mp4"

then i would only get

"http://megavideo.com/g7987bfd0fg .mp4"

i know there is some way to start at a certain character in a document and go forward or backward a few characters, but the problem arises when you dont know how many characters to go back due to varying lengths of URLs... is there some way that you could search for http:// and then search for .mp4 and then highlight everything in between them?

#EDIT# I also need to be able to feed this URL into another process that will download the file using "httpwebrequest" and "httpwebresponse" so it would be ideal if i could do something like:

textbox3.text = extracted link

Thanks in advance!


Your best bet is Regular Expressions. Get the app called RegexBuddy. It will help you write the regular expression for your needs

Try this code

Dim input As String= "Your initial page source that you want to search through"
Dim pattern As String = "http\:\/\/[.]*\.mp4"

Dim rgx As New Regex(pattern, RegexOptions.IgnoreCase)
Dim matches As MatchCollection = rgx.Matches(input)
If matches.Count > 0 Then
   For Each match As Match In matches
      DownloadVideo(match.Value)
   Next   
End If 


What I would do is do a regular expression match to find the string I was looking for.

here's an example for begins with Regex pattern for checking if a string starts with a certain substring?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜