Saturday, November 28, 2009

Hack 78. Find Links to Any Web Site

Yahoo! can tell you which sites link to any other site, and yLinkbacks uses Yahoo! Search Web Services to find links to the current page you're browsing.

When you browse to a web site you've never seen before, you don't have very much advance knowledge about the site. You might know that you've followed a link from a particular site that you read frequently, or you might have found the site in some search results for a certain search term. Of course, the site itself can tell you quite a bit, but that still doesn't give you any clues about where the site fits into the larger Web. With some searching at Yahoo!, you can get extra info about a site by using the special link: syntax.

If you want to find what sites are linking to any other particular site, you can browse to http://search.yahoo.com and enter this query: link:insert URL. Instead of standard search results, Yahoo! will display a list of the sites that link to the URL you've specified in the query. For example, if you'd like to find out where the O'Reilly Hacks site fits into the Web, you could search for link:http://hacks.oreilly.com.

In the results, you immediately get a sense of how many pages link to the site and what kinds of sites are linking there. If you're browsing the Web, leaving a site to do a quick Yahoo! link: search can be annoying if you'd just like to get this sense about the current site you're visiting. To find the sites, you need to copy the current URL from your browser address bar, open a new window or tab, browse to Yahoo!, and then assemble the proper query. It's a quick process, but you can speed it up considerably with a bit of classic ASP and a JavaScript bookmarklet.

This hack uses JavaScript to get the URL of the current page you're viewing in your browser. From there, it passes the URL to a server-side script that assembles the proper Yahoo! query and fetches the top 10 results with Yahoo! Search Web Services. A new pop-up window will give a quick look at which sites are linking to the current page, without leaving your place.

5.3.1. The Code
The first part of this hack is a server-side script that retrieves the search results and formats them for display. The HTML result will end up being inserted into a separate pop-up browser window above the current page.

The script accepts a URL with the querystring variable q. From there, it creates a Yahoo! Search Web Services URL using the special link: syntax.

To create the script, save the following code to a file called yl.asp and be sure to include your own unique application ID in the code:




Yahoo Linkbacks





<%

On Error Resume Next
Response.Buffer = True
'' Expecting a URL string to be in the querystring "q"
szQ = Request("q")
If (szQ <> "") Then %>




style='font-weight:bold;text-align:center;width:98%;padding-top:20px;'>
Loading…

<% Response.Flush %>



    <% Dim objXML, xml
    szStr = ""
    szUrl = ""
    szTitle = ""

    szSummary = ""
    set xml = Server.CreateObject ("MSXML2.ServerXMLHTTP.3.0")

    szGetString = ("http://api.search.yahoo.com/" &_
    "WebSearchService/V1/webSearch?" &_
    "appid=[YOUR_APPLICATION_ID ]&results=10&query=link :" & szQ)

    xml.Open "GET", szGetString, False
    xml.Send
    set objXML = xml.responseXML

    If (objXML.getElementsByTagName("Result").length>0) Then
    If (objXML.getElementsByTagName("Result").length>10) Then
    nLen = 10
    Else

    nLen = objXML.getElementsByTagName("Result").length-1
    End if
    For z = 0 to nLen

    '' Get each "Result" Node and loop through
    '' its childNodes to get Url, Title and Summaries
    Set nGb = objXML.getElementsByTagName("Result")(z)
    set o18 = nGb.childNodes
    For k = 0 to o18.length-1
    Select Case (o18.item(k).nodeName)
    Case "Title"
    szTitle = o18.item(k).text
    Case "Summary"
    szSummary = o18.item(k).text
    Case "Url"
    szUrl = o18.item(k).text
    End Select
    Next

    If (szSummary <> "") Then szSummary = ": " & szSummary

    szStr = szStr & ("
  • " & szTitle &
    "
    ")
    szStr = szStr & (szSummary & "
  • ")

    szUrl = ""
    szTitle = ""
    szSummary = ""

    Next
    End if
    If (szStr <> "") Then
    Response.write(szStr)
    Else
    Response.write("
  • No Results Found
  • ")
    End if

    set xml = Nothing
    set objXML = Nothing
    End if %>




website-hit-counters.com
Provided by website-hit-counters.com site.







Upload yl.asp to a public web server to make it available to the bookmarklet. The bookmarklet is a bit of JavaScript that resides in a bookmark and calls the ASP page in-context by sending the URL of the page currently in the browser.

5.3.2. Running the Hack
Add the following code to an existing bookmarklet by adding it to the location field. Be sure to include the URL of the server-side page, yl.asp:

javascript:function p(){window.open(('http://example.com/yl. asp?q='+
document.location. href),'nsm','width=250,height=350,directories=no,
location=no,menubar=no, scrollbars=yes,status=no,toolbar=no,
resizable=no,left=0,top=0,screenx=0,screeny=0')}p()














1 comment:

  1. Great hackings tips i was use it its really amazing and succesful so when you update ur blog than inform me.Good job

    Thanks

    ReplyDelete