Red facehow to make it work automatically ?

Posts 1–15 of 22 · Page 1 of 2
how to make it work automatically ?
Hello.
Do you know how to work backgroundworker with this code?

The request would be as I pulled out of google with a background worker and if so it is possible to collect links from google pagination.

Not in label or how I'm new for that.
I just want To make go to next page like 1,2,3,4,5,6,7,8,9 and so on clicking button and make it go itself and pick up links through all pages with background worker or timer or how to make it work automatically as i said i'm new.
Like google has pagination.
It only goes through one page and stop on first number and do not move
far.

Thank you.

Code:
Private Sub WebBrowser1_DocumentCompleted (ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
         If (WebBrowser1.ReadyState WebBrowserReadyState.Complete =) Then
             For Each ClientControl I HtmlElement In WebBrowser1.Document.Links
                 IF NOT ClientControl.GetAttribute ("href"). Contains (Google) And ClientControl.GetAttribute ("href"). Contains ("http") and ClientControl.GetAttribute ("href"). Contains ("http") Then
                     ListBox1.Items.Add (ClientControl.GetAttribute ('href'))
                 end If
             Next
         end If

   end Sub

Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
         WebBrowser1.Navigate (http://www.google****/search?num=100&q = "& ComboBox1.Text)
         BackgroundWorker1.RunWorkerAsync ()
     end Sub

Private Sub BackgroundWorker1_DoWork (ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
         For i = 0 to 100
             Threading.Thread.Sleep (200)
             BackgroundWorker1.ReportProgress (i)
         Next

     end Sub

     Private Sub BackgroundWorker1_ProgressChanged (ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
         Label1.Text = e.ProgressPercentage
     end Sub
If do not understand what i mean to say so here is the example of that i want to get.

If you want to retreive the results from a google search, use the Google API.

It sure can be done with string formatting, that is not very effective though..

http://code.google.com/p/google-api-for-dotnet/

[highlight="C"] // Search 32 results of keyword : "Google APIs for .NET"
GwebSearchClient client = new GwebSearchClient(/* Enter the URL of your site here */);
IList<IWebResult> results = client.Search("Google API for .NET", 32);
foreach(IWebResult result in results)
{
Console.WriteLine("[{0}] {1} => {2}", result.Title, result.Content, result.Url);
} [/highlight]

Should be something like

[highlight="VB.Net"]

Dim client as new GwebSearchClient("Enter the url of your site here")
Dim result as list(of IWebResult) = client.Search("Google API for .Net", 32)

for each result as IWebResult in results
msgbox(String.Format("[{0} {1} => {2}]",result.title,result.content,result.url))
next[/highlight]
with api not working and it does not do all good job i have made it program with google api alpha but it only collects 64 link only.

With this method you see in the picture it is the best.
I do not even know hot to search through google and what keywords type to find the answer

I just can tell no one can help even microsoft i asked from their forum no answer.
So any help would be great

I'm new.

Here is my api program and it's not to like to me

http://s1.postimage.org/9zl3l1xpp/no..._are_happy.png
Quote Originally Posted by polas6 View Post
with api not working and it does not do all good job i have made it program with google api alpha but it only collects 64 link only.

With this method you see in the picture it is the best.
I do not even know hot to search through google and what keywords type to find the answer

I just can tell no one can help even microsoft i asked from their forum no answer.
So any help would be great

I'm new.

Here is my api program and it's not to like to me

http://s1.postimage.org/9zl3l1xpp/no..._are_happy.png
Dim result as list(of IWebResult) = client.Search("Google API for .Net", 32)

Try changing 32 to whatever you want(how many results you want to have).
Do you mean this code ?


Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Process.Start(ListBox1.SelectedItem.ToString())
End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
ListBox1.Items.Clear()
ListBox1.BackColor = Color.Black
ListBox1.ForeColor = Color.WhiteSmoke
Me.Text = "Working..."

Dim gwebsearcher As New Google.API.Search.GwebSearchClient("http://www.google.com" + TextBox1.Text)
Dim results As IList(Of Google.API.Search.IWebResult) = gwebsearcher.Search(TextBox1.Text, 100, "English", "Off")

For Each item As Google.API.Search.IWebResult In results
ListBox1.Items.Add(item.Url)
ListBox1.Items.Add(item.Title)
ListBox1.Items.Add(vbNewLine)
Next

Me.Text = "Done!!"



End Sub
Private Sub OpenApplicationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenApplicationToolStripMenuItem.Click
Form2.Show()
End Sub


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F1 Then
Form2.Show()
End If
End Sub

2 forma

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
WebBrowser1.Navigate("http://www.google.com/webhp?hl=en#sclient=psy&hl=en&site=webhp&source=hp &q=http:%2F%2Fwww+%2B+rar+&q=" + TextBox1.Text)
End Sub

I told you this is not working my friends.

Oops! Sorry.
Yep, try changing the following line:

Dim results As IList(Of Google.API.Search.IWebResult) = gwebsearcher.Search(TextBox1.Text, 100, "English", "Off")

Change the 100 to how many results you want to have.
no work.
It give me the same 64 results.
I tried to find new code but it the same and still doesn't work.
This is a manual solution that I wrote a while ago when I was new to VB which is not as efficient as using a proper API but it's sufficient. It will only get the URLs btw.
[highlight=vb.net]Private Function GetGoogleResults(ByVal searchString As String, ByVal pageNumber As String) As List(Of String)
Dim lstLinks As New List(Of String)
Dim pgSource As String = String.Empty
Using wc As New Net.WebClient
pgSource = wc.DownloadString("http://www.google.com/search?q=" & searchString & "&start=" & ((pageNumber - 1) * 10))
End Using

Dim hrefRegex As New Regex("href=""[^""]+")
Dim googleRegex As New Regex("http://[^\.]+.google(usercontent)*.com/.*")
For Each m As Match In hrefRegex.Matches(pgSource)
Dim sLink As String = m.Value.Split(""""c)(1)
If googleRegex.IsMatch(sLink) Or Not sLink.StartsWith("http://") Then Continue For
lstLinks.Add(sLink)
Next
Return lstLinks
End Function[/highlight]

Usage:
GetGoogleResults("lol", 1)

Just make it keep running the function over and over, increasing the page by 1. Make sure to check if the links are the same as the previous page, because it means there are no more page results. For some reason, Google did this to probably patch old web crawlers or something.

This is one way that I quickly wrote but it's pretty ugly, there probably is a neater solution.
[highlight=vb.net]
Dim oldSearchResults As New List(Of String)
Private Sub DoStuffs()
Dim bLinksAreSame As Boolean = False
Dim currentPage As Integer = 1
While Not bLinksAreSame
Dim lstGoogleLinks As List(Of String) = GetGoogleResults("blah", currentPage)
If lstGoogleLinks.Count = oldSearchResults.Count Then
For i As Integer = 0 To lstGoogleLinks.Count - 1
If lstGoogleLinks(i) <> oldSearchResults(i) Then Exit For
If i = oldSearchResults.Count - 1 Then bLinksAreSame = True
If bLinksAreSame Then Exit For
Next
End If
If bLinksAreSame Then Exit While
For Each link In lstGoogleLinks
MsgBox(link) 'Do something with the links here
Next
oldSearchResults = lstGoogleLinks
currentPage += 1
End While
End Sub
[/highlight]
Yap,yap where is button,textbox,listbox where to put this code ?
I just told you i'm new for this i do not understand about fuction and so on.
Code:
Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Function GetGoogleResults(ByVal searchString As String, ByVal pageNumber As String) As List(Of String)
        Dim lstLinks As New List(Of String)
        Dim pgSource As String = String.Empty
        Using wc As New Net.WebClient
            pgSource = wc.DownloadString("http://www.google.com/search?q=" & searchString & "&start=" & ((pageNumber - 1) * 10))
        End Using

        Dim hrefRegex As New Regex("href=""[^""]+")
        Dim googleRegex As New Regex("http://[^\.]+.google(usercontent)*.com/.*")
        For Each m As Match In hrefRegex.Matches(pgSource)
            Dim sLink As String = m.Value.Split(""""c)(1)
            If googleRegex.IsMatch(sLink) Or Not sLink.StartsWith("http://") Then Continue For
            lstLinks.Add(sLink)
        Next
        Return lstLinks
    End Function

    Dim oldSearchResults As New List(Of String)
    Private Sub DoStuffs()
        Dim bLinksAreSame As Boolean = False
        Dim currentPage As Integer = 1
        While Not bLinksAreSame
            Dim lstGoogleLinks As List(Of String) = GetGoogleResults("blah", currentPage)
            If lstGoogleLinks.Count = oldSearchResults.Count Then
                For i As Integer = 0 To lstGoogleLinks.Count - 1
                    If lstGoogleLinks(i) <> oldSearchResults(i) Then Exit For
                    If i = oldSearchResults.Count - 1 Then bLinksAreSame = True
                    If bLinksAreSame Then Exit For
                Next
            End If
            If bLinksAreSame Then Exit While
            For Each link In lstGoogleLinks
                ListBox1.Items.Clear()
                ListBox1.BackColor = Color.Black
                ListBox1.ForeColor = Color.WhiteSmoke
                Me.Text = "Working..."

                Dim gwebsearcher As New Google.API.Search.GwebSearchClient("http://www.google.com" + TextBox1.Text)
                Dim results As IList(Of Google.API.Search.IWebResult) = gwebsearcher.Search(TextBox1.Text, 100, "English", "Off")

                For Each item As Google.API.Search.IWebResult In results
                    ListBox1.Items.Add(item.Url)
                    ListBox1.Items.Add(item.Title)
                    ListBox1.Items.Add(vbNewLine)
                Next
            Next
            oldSearchResults = lstGoogleLinks
            currentPage += 1
        End While
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Add(GetGoogleResults("what em i doing wrong ?", 1))
    End Sub
Quote Originally Posted by polas6 View Post
Code:
Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Function GetGoogleResults(ByVal searchString As String, ByVal pageNumber As String) As List(Of String)
        Dim lstLinks As New List(Of String)
        Dim pgSource As String = String.Empty
        Using wc As New Net.WebClient
            pgSource = wc.DownloadString("http://www.google.com/search?q=" & searchString & "&start=" & ((pageNumber - 1) * 10))
        End Using

        Dim hrefRegex As New Regex("href=""[^""]+")
        Dim googleRegex As New Regex("http://[^\.]+.google(usercontent)*.com/.*")
        For Each m As Match In hrefRegex.Matches(pgSource)
            Dim sLink As String = m.Value.Split(""""c)(1)
            If googleRegex.IsMatch(sLink) Or Not sLink.StartsWith("http://") Then Continue For
            lstLinks.Add(sLink)
        Next
        Return lstLinks
    End Function

    Dim oldSearchResults As New List(Of String)
    Private Sub DoStuffs()
        Dim bLinksAreSame As Boolean = False
        Dim currentPage As Integer = 1
        While Not bLinksAreSame
            Dim lstGoogleLinks As List(Of String) = GetGoogleResults("blah", currentPage)
            If lstGoogleLinks.Count = oldSearchResults.Count Then
                For i As Integer = 0 To lstGoogleLinks.Count - 1
                    If lstGoogleLinks(i) <> oldSearchResults(i) Then Exit For
                    If i = oldSearchResults.Count - 1 Then bLinksAreSame = True
                    If bLinksAreSame Then Exit For
                Next
            End If
            If bLinksAreSame Then Exit While
            For Each link In lstGoogleLinks
                ListBox1.Items.Clear()
                ListBox1.BackColor = Color.Black
                ListBox1.ForeColor = Color.WhiteSmoke
                Me.Text = "Working..."

                Dim gwebsearcher As New Google.API.Search.GwebSearchClient("http://www.google.com" + TextBox1.Text)
                Dim results As IList(Of Google.API.Search.IWebResult) = gwebsearcher.Search(TextBox1.Text, 100, "English", "Off")

                For Each item As Google.API.Search.IWebResult In results
                    ListBox1.Items.Add(item.Url)
                    ListBox1.Items.Add(item.Title)
                    ListBox1.Items.Add(vbNewLine)
                Next
            Next
            oldSearchResults = lstGoogleLinks
            currentPage += 1
        End While
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Add(GetGoogleResults("what em i doing wrong ?", 1))
    End Sub
ListBox1.Items.AddRange(GetGoogleResults("Blablabl a", 1))

Try using the DoStuffs sub in your click event...
This do not work ListBox1.Items.AddRange(GetGoogleResults("Blablabl a", 1))
I get error here is the error i tried to use in even click dostuff and get more errors.
It tells me you cannot use it this argument code or something similar.

Quote Originally Posted by polas6 View Post
This do not work ListBox1.Items.AddRange(GetGoogleResults("Blablabl a", 1))
I get error here is the error i tried to use in even click dostuff and get more errors.
It tells me you cannot use it this argument code or something similar.

That sure helps me a lot. A line that is underlined in blue. Great error description.
Ok i got how it is working i put code like this but the problem now here.

Please help me to fix it.

Here is the code and how i put it to work but i get error.

Code:
Imports System.Text.RegularExpressions
Public Class Form1
    Private Function GetGoogleResults(ByVal searchString As String, ByVal pageNumber As String) As List(Of String)
        Dim lstLinks As New List(Of String)
        Dim pgSource As String = String.Empty
        Using wc As New Net.WebClient
            pgSource = wc.DownloadString("http://www.google.com/search?q=" & searchString & "&start=" & ((pageNumber - 1) * 10))
        End Using

        Dim hrefRegex As New Regex("href=""[^""]+")
        Dim googleRegex As New Regex("http://[^\.]+.google(usercontent)*.com/.*")
        For Each m As Match In hrefRegex.Matches(pgSource)
            Dim sLink As String = m.Value.Split(""""c)(1)
            If googleRegex.IsMatch(sLink) Or Not sLink.StartsWith("http://") Then Continue For
            lstLinks.Add(sLink)
        Next
        Return lstLinks
    End Function

    Dim oldSearchResults As New List(Of String)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim bLinksAreSame As Boolean = False
        Dim currentPage As Integer = 1
        While Not bLinksAreSame
            Dim lstGoogleLinks As List(Of String) = GetGoogleResults("blah", currentPage)
            If lstGoogleLinks.Count = oldSearchResults.Count Then
                For i As Integer = 0 To lstGoogleLinks.Count - 1
                    If lstGoogleLinks(i) <> oldSearchResults(i) Then Exit For
                    If i = oldSearchResults.Count - 1 Then bLinksAreSame = True
                    If bLinksAreSame Then Exit For
                Next
            End If
            If bLinksAreSame Then Exit While
            For Each link In lstGoogleLinks
                ListBox1.Items.Clear()
                ListBox1.BackColor = Color.Black
                ListBox1.ForeColor = Color.WhiteSmoke
                Me.Text = "Working..."

                Dim gwebsearcher As New Google.API.Search.GwebSearchClient("http://www.google.com" + TextBox1.Text)
                Dim results As IList(Of Google.API.Search.IWebResult) = gwebsearcher.Search(TextBox1.Text, 100, "English", "Off")

                For Each item As Google.API.Search.IWebResult In results
                    ListBox1.Items.Add(item.Url)
                    ListBox1.Items.Add(item.Title)
                    ListBox1.Items.Add(vbNewLine)
                Next
            Next
            oldSearchResults = lstGoogleLinks
            currentPage += 1
        End While
    End Sub
Thank you.

I can see where the error occurred and that it shows how to correct but the problem is that my service missing from help and support component (
That's why I can not fix the error.
That code works fine for me. Try adding the library from the DotNet directory rather than the DotNet20...shouldn't be that, but worth a try.

Your code looks kinda like you don't really know where to put what lol.
Posts 1–15 of 22 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us