Skip to content

Instantly share code, notes, and snippets.

@facebookegypt
Last active August 25, 2016 00:46
Show Gist options
  • Select an option

  • Save facebookegypt/8ceed5db9a9c04697ee4011aae80fa05 to your computer and use it in GitHub Desktop.

Select an option

Save facebookegypt/8ceed5db9a9c04697ee4011aae80fa05 to your computer and use it in GitHub Desktop.
Get a spacific link url from a webpahe HTML
Imports System
Imports System.Net
Imports System.Net.WebClient
Public Class Form1
Dim tLINK As String = "http://network.bepress.com/explore/?q=&facet=download_type%3A%22PDF%22&facet=discipline%3A%22Law%22"
Dim Inext30 As Integer = 30
Dim Hlink As String
Public RawHtmlLinks As String
Dim ThisAttrib As String = "fbTooltip"
Dim Link
Public Function StripHtml(htmlContentLines() As String) As String
Dim iStartIndex, iEndIndex As Integer '// used to locate content to extract.
For Each htmlLine As String In htmlContentLines '// loop thru all lines.
If htmlLine.Contains("class=" & ThisAttrib) Then '// locate lines that contain your links.
iStartIndex = htmlLine.IndexOf("http://") '// get start location of link.
iEndIndex = htmlLine.IndexOf("""", iStartIndex) '// get end location of link.
Hlink &= vbCrLf & (htmlLine.Substring(iStartIndex, iEndIndex - iStartIndex)) '// extract link.
End If
Next
Return Hlink
End Function
Sub getdiv()
Dim I As Integer = 0
Dim divs = WB1.Document.Body.GetElementsByTagName("A")
For Each d As HtmlElement In divs
If InStr(d.GetAttribute("classname").ToString, ThisAttrib, CompareMethod.Text) Then
I += 1
T2.Text += vbCrLf & I & ("- ") & d.InnerText
RawHtmlLinks += vbCrLf & d.OuterHtml
End If
'link : http://network.bepress.com/explore/?q=&facet=download_type%3A%22PDF%22&facet=discipline%3A%22Law%22
Next
T4.Text = StripHtml(RawHtmlLinks.Split(vbCrLf))
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
WB1.Navigate(tLINK)
Do While WB1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
T2.Text = ""
getdiv()
End Sub
Private Sub s_Click(sender As System.Object, e As System.EventArgs) Handles s.Click
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'link : http://network.bepress.com/explore/?q=&facet=download_type%3A%22PDF%22&facet=discipline%3A%22Law%22&start=30
T5.Text &= (T4.Text) & vbCrLf
WB1.Navigate(T1.Text & "&start=" & Inext30)
T2.Text = ""
RawHtmlLinks = ""
Inext30 += 30
getdiv()
Label4.Text = Inext30
End Sub
Private Sub WB1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WB1.DocumentCompleted
'link : http://network.bepress.com/explore/?q=&facet=download_type%3A%22PDF%22&facet=discipline%3A%22Law%22&start=30
T5.Text &= (T4.Text) & vbCrLf
WB1.ScriptErrorsSuppressed = True
tLINK = "http://network.bepress.com/explore/?q=&facet=download_type%3A%22PDF%22&facet=discipline%3A%22Law%22&start=" & Inext30
WB1.Navigate(tLINK)
T2.Text = ""
RawHtmlLinks = ""
Inext30 += 30
getdiv()
Label4.Text = Inext30
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment