User LoL Posted February 9, 2014 at 06:54 AM Report #544517 Posted February 9, 2014 at 06:54 AM (edited) Olá, é tenho um rich com um código fonte e preciso criar um método automático de busca de link, as regras são as seguintes, o link sempre irá terminar em "/previsao.avi" e o início é "http://", ou seja, não tem como saber quantos caracteres são porque varia, só o inicio e o fim do link serao sempre iguais. Por exemplo, uma hora o link pode ser "http://www.algumacoisa.com/32832/previsao.avi" outra hora pode ser "http://www.outracoisa.com/test/2933/previsao.avi". Não estou conseguindo pegar esse link. E quando conseguir, tem algum método de baixar esse arquivo ".avi" que está no link? Obrigado desde já Edited February 9, 2014 at 06:54 AM by User LoL
nelsonr Posted February 9, 2014 at 12:17 PM Report #544523 Posted February 9, 2014 at 12:17 PM (edited) Boas, podes usar regular expressions para extrair os links. Exemplo: Dim text As String = "texto com os links" Dim listaEnderecos As New List(Of String) ' Dim regx As New Regex("http://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?", RegexOptions.IgnoreCase) Dim matches As MatchCollection = regx.Matches(text) For Each match As Match In matches listaEnderecos.Add(match.Value) Next A lista listaEnderecos vai conter os links extraidos Edited February 9, 2014 at 12:17 PM by nelsonr 1 Report
User LoL Posted February 9, 2014 at 12:41 PM Author Report #544525 Posted February 9, 2014 at 12:41 PM Obrigado, adaptei ele e funcionou certinho, faz uma lista dos links que contém o final ".avi",tem algum modo de fazer download desse arquivo pelo próprio vb.net?
nelsonr Posted February 9, 2014 at 03:47 PM Report #544544 Posted February 9, 2014 at 03:47 PM Podes usar o My.Computer.Network.DownloadFile http://msdn.microsoft.com/en-us/library/1say4ws7.aspx
User LoL Posted February 9, 2014 at 09:37 PM Author Report #544589 Posted February 9, 2014 at 09:37 PM Obrigado. Agora so tenho mais uma dúvida, não estou conseguindo usar o Regular Expressions para selecionar um valor entre uma tag. Preciso pegar o texto que estiver depois de " <PRE CLASS="western"> " e antes de " </PRE> ". Tentei assim, mas não deu certo: Dim text As String = RichTextBox1.Text Dim listaEnderecos As New List(Of String) ' Dim regx As New Regex("<PRE CLASS=""western"">([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)</PRE>", RegexOptions.IgnoreCase) Dim matches As MatchCollection = regx.Matches(text) For Each match As Match In matches listaEnderecos.Add(match.Value) ListBox1.Items.Add(match.Value) Next
User LoL Posted February 14, 2014 at 10:10 PM Author Report #545346 Posted February 14, 2014 at 10:10 PM Alguém tem uma sugestão? Pesquisei vários dias e não consegui, oque eu quero é só pegar o texto estiver depois de "<PRE CLASS="western">" e antes de " </PRE> ".
nelsonr Posted February 15, 2014 at 03:26 PM Report #545383 Posted February 15, 2014 at 03:26 PM Podes fazer algo assim: Dim listaConteudo As New List(Of String) Dim regx As New Regex("<PRE[a-zA-Z ""=]*>(?<content>.*?)<\/PRE>") Dim matches As MatchCollection = regx.Matches(RichTextBox1.Text) For Each match As Match In matches listaConteudo.Add(match.Groups("content").Value) Next
User LoL Posted February 15, 2014 at 07:09 PM Author Report #545413 Posted February 15, 2014 at 07:09 PM Não está funcionando. Não sei se leva em consideração, mas o texto é multiline, ou seja, o <PRE começa em uma linha, e o </PRE> termina em outra linha, eu preciso passar pra um rich o texto que estiver no meio
nelsonr Posted February 15, 2014 at 09:40 PM Report #545424 Posted February 15, 2014 at 09:40 PM Se tem mudança de linha, experimenta com esta pattern Dim listaConteudo As New List(Of String) Dim regx As New Regex("<PRE[a-zA-Z ""=]*>(?<content>(.|\n)*?)<\/PRE>") Dim matches As MatchCollection = regx.Matches(texto) For Each match As Match In matches listaConteudo.Add(match.Groups("content").Value) Next
User LoL Posted February 16, 2014 at 03:43 AM Author Report #545445 Posted February 16, 2014 at 03:43 AM Funcionou, obrigado. Só preciso adicionar um método de codificar pra utf8 o texto que o programa baixa
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now