Results 1 to 5 of 5

Thread: [RESOLVED] Facebook Search

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Resolved [RESOLVED] Facebook Search

    So I am trying to use the search bar on the the face book page and I am stuck. I don't even know if Facebook allows it. This is what I am using right now. It places the text in the box, but it wont invoke the click

    Code:
    Try
                WebBrowser1.Document.GetElementById("q").SetAttribute("Value", txtEmail.Text) 'Fills the Search field on the website
                WebBrowser1.Document.GetElementById("Search").InvokeMember("click") 'Submits the information filled
            Catch ex As Exception
    
            End Try

  2. #2
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Facebook Search

    sometimes you need a "pause" so that it has time to show up in the textbox before the click is submitted. try adding a timer with an interval of 1000 and put the "click" line of code in the timer's tick event. leave the textbox line where it's at. see if it works then. this all assumes that the search button has an ID of "Search" btw. Usually the ID for form submit buttons will be "Submit".

    EDIT: The HTML for that submit button is:

    Code:
    <button type="submit" onclick="var q = $(&quot;q&quot;);if (q.value == q.getAttribute(&quot;placeholder&quot;)) {q.focus(); return false;}" title="Search"><span class="hidden_elem">Search</span></button>
    It does not have an ID, so you're trying to click something that isn't there. What you'll need to do is loop through the HTMLCollection's "input" tags and test to see if the "title" attribute is equal to "Search". Once it is, you know you have the right button and can perform the click.

    something like:

    vb.net Code:
    1. Dim webBrowserDocument As HtmlDocument = webBrowser.Document
    2. Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
    3. For Each element As HtmlElement In hec
    4.   If String.Compare(element.GetAttribute("title"), "Search") = 0 Then 'Found it
    5.        'Click it here
    6.   End if
    7. Next

    Untested, but should be close.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Re: Facebook Search

    I got it working by using their url structure
    Code:
     Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
                   Dim email As String
            email = txtEmail.Text.Replace("@", "&#37;40")
            WebBrowser1.Navigate("http://www.facebook.com/search/?o=2048&q=" & email)
        End Sub

  4. #4

  5. #5

    Re: [RESOLVED] Facebook Search

    Aside from the advanced search option that Facebook has, there is another search option that you can use if you want to look for networks. Type “facebook.network/network.php” in the browser bar or URL and then you can search for that network you’re looking for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width