나는 (안 사악한 목적을 위해, 그냥 개인적인 프로젝트의) 해적 베이 URL의 첫 번째 링크를 클릭하려고하고 내가 그것을 할 수있는 최선의 방법인지 궁금하네요 :VB.Net에서 링크를 클릭하는 가장 효율적인 방법은 무엇입니까?
For Each ele As HtmlElement In WebBrowser1.Document.Links
If ele.GetAttribute("href").Contains("magnet") Then
ele.InvokeMember("click")
Exit For
End If
Next
내가 이것이 페이지의 첫 번째 자석 링크를 클릭하는 가장 좋은 방법인지 궁금 합니다만, 현재 웹 브라우저를 사용하고 있습니다. 그러나이를 수행 할 수 있는지 알고 싶습니다. 어쩌면 HTTP 요청이나 그 라인을 따라 무엇인가?
Dim PBsource As String = New System.Net.WebClient().DownloadString("http://pirateproxy.se/search/ubuntu/0/7/0")
MsgBox(PBsource)
그러나 아무것도 메시지 박스에 표시되지 않습니다, 그냥 빈입니다, 내가 잘못 URL을 전달하고있다 :
* 편집 GJKH *
에 대한이 같은 코드가?
* 편집 *
2를 내 버튼 하위에서이 코드를 가지고 :
Imports System.Text.RegularExpressions
Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Dim PBsource As String = New System.Net.WebClient().DownloadString("http://pirateproxy.se/search/ubuntu/0/7/0")
MsgBox(PBsource)
Dim strReg As String
'Regex to get a herf links
strReg = "<a\s+href\s*=\s*""?([^"" >]+)""?>(.+)</a>"
Dim reg As New Regex(strReg, RegexOptions.IgnoreCase)
Dim m As Match = reg.Match(PBsource)
Dim magnetURL As String = ""
'Keep going while we hit regex matches
While m.Success
If m.Groups(1).Value.ToString.Contains("magnet") Then
'Match found, assign magnetURL and exit while
magnetURL = m.Groups(1).ToString
Exit While
End If
'Match not found, move to next match
m = m.NextMatch()
End While
If Not magnetURL Is String.Empty Then
Using wc As New System.Net.WebClient
wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
PBsource = wc.DownloadString("magnet:?xt=urn:btih:1e4dae83371ba704d5d89e1828068ef0c4151e32&dn=Steam+OS+Official+Installer&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337")
MsgBox(PBSource)
End Using
Else
MsgBox("no magnet URL found")
End If
End Sub
그러나이 PBSource 올바르게 설정되고 있지 않습니다 보인다 상관없이. 공백 문자열이 생깁니다.
당신은 페이지를 얻을 다음 HTMLAgilityPack를 사용하여 구문 분석 할 수있는 귀하의 코드가 사방에, 내 업데이트 된 대답을 참조 단지 복사되는 링크 –
및 붙여 넣기 "를 클릭". – GJKH
@GJKH 고마워, 나는 원래 여기서부터는 루프를 배우기위한 프로젝트로 시작했다. 그것이 완벽하게 도움이 감사 감사 지금. – SCGB