使用 VB.net 将变量定义为页面源中的 url?

发布于 2024-11-03 06:22:37 字数 965 浏览 1 评论 0原文

我在 VB.net 中编写一个程序,该程序包含三个主要步骤:

步骤 1:在文本框 1 中显示正在播放电影的网页的源代码。

第 2 步:在源代码中突出显示该电影的 URL,然后在 textbox3 中仅显示该 URL。

步骤 3:使用 HttpWebRequestHttpWebResponse 将电影下载到用户定义的目录

问题是我不知道如何有效地从源代码中提取 URL。也许我可以尝试在源代码中搜索字符串“.mp4”或“.avi”或其他视频扩展名,但这只会找到链接的末尾,我如何突出显示整个链接?

例如:如果我在源代码中搜索“.mp4”,并且有一个 URL,例如

“http://megavideo.com/g7987bfd0fg.mp4”

那么我只会得到

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

我知道有某种方法可以从文档中的某个字符开始,然后向前或向后移动几个字符,但是当您不知道要向后移动多少个字符时,就会出现问题不同长度的 URL...是否可以通过某种方式搜索 http://,然后搜索 .mp4,然后突出显示它们之间的所有内容

? >#EDIT# 我还需要能够提供此 URL进入另一个进程,该进程将使用“httpwebrequest”和“httpwebresponse”下载文件,因此如果我可以执行以下操作,那就太理想了:

textbox3.text = extracted link

提前致谢!

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 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

混吃等死 2024-11-10 06:22:37

最好的选择是正则表达式。获取名为 RegexBuddy 的应用程序。它将帮助您编写满足您需要的正则表达式

尝试此代码

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 

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 
不及他 2024-11-10 06:22:37

我要做的就是进行正则表达式匹配来查找我要查找的字符串。

这是一个以 正则表达式模式开头的示例用于检查字符串是否以某个子字符串开头?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文