Click here to Skip to main content
15,173,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to deal with google search api to return a list of url.

like i want to search for the word : mobile
so it will return to me a list of all the url would appear in
just the url ... I didn't use google search api before

so any one can help me ?

note : i need it in c# language.
note 2 : i need all the url that appear in search.

The URL to search example string "hello world" is :[^]

Use this with HttpWebRequest and read the response. After that there will be some work to do to extract the information.
ENG.Samy Sammour 18-Dec-14 18:26pm
its return a page result if i put it in a label so it will be google page but the thing i want is only the search url result

just a list of url
ENG.Samy Sammour 18-Dec-14 18:41pm
i put the code result in a textbox and found manually the link but is there a way to find all the url written there in some function ?

        public ActionResult GetResult(string term)
            string apiKey = "Your api key";
            string cx = "your search key";
            string query = term;

            WebClient webClient = new WebClient();
            webClient.Headers.Add("user-agent", "Only a test!");

            var results = webClient.DownloadString(String.Format("{0}&cx={1}&q={2}&alt=json", apiKey, cx, query));

           // web.Dispose();
            return Json(results);


  <form id="form1">
        <table width="100%">
                <td colspan="2">
                    <input id="srchterm" type="text" style="width:500px" />
                    <button >Search</button>
            <tr align="left">
                <td style="width:50%">
                    <div class="demo-container"></div>
                <td align="center" style="width:50% !important;">
                    <div id="divResultPreview" class="divresultpreview">

                    <div id="divLoading" style="margin: 0px; padding: 0px; removed: fixed; removed 0px;<br mode=" hold=" />                    top: 0px; width: 100%; height: 100%; background-color: #333333; z-index: 30001;<br mode=">

<p style="removed: absolute; removed 40%; removed 40%; color: White;font-size:medium">
    Loading, please wait...<br /><img src="http://localhost:54539/Content/loading-image.gif">

<script type="text/javascript" language="javascript">
    function SearchWeb() {
        try {
            var url = '@Url.Action("GetResult", "Home")';
            var term = $("#srchterm").val();
            $.post(url, { term: term },
           function (data) {
               var obj = jQuery.parseJSON(data);
               var strHtml = "";
               if (obj.items.length > 0) {
                   for (var i = 0; i < obj.items.length; i++) {
                       strHtml = strHtml + "<table id="\"restable"" i="" style="\"border:0px\""><tr><td><fieldset style="\"border-style:none\"" ><a href="\""" style="\"font-size:medium;margin:2px;\"">" + obj.items[i].title + "</a><br />";
                       strHtml = strHtml + "<label style="\"color:Green;style=\"font-size:x-small;margin:2px;\"">" + obj.items[i].link + "</label><br />";
                       strHtml = strHtml + "<label style="\"color:Blue;margin:2px;\"">" + obj.items[i].htmlSnippet + "</label><br />";
                       strHtml = strHtml + "<label id="\"lblCacheUrl"" i="" style="\"display:none\"">" + obj.items[i].displayLink + "</label>";
                       strHtml = strHtml + "</fieldset></td><td>";
                       strHtml = strHtml + "<img id="\"showimg"" i="" src="\"\"" style="\"filter:" ></img></td></tr></table>";
        } catch (err) { }
King Fisher 23-Feb-15 4:16am
Why are you answering two months old Question?
    (function () {
        var cx = '001111315940323651598:b5c5-62jb84';
        var gcse = document.createElement('script'); gcse.type = 'text/javascript';
        gcse.async = true;
        gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
            '//' + cx;
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(gcse, s);
</script><pre lang="HTML">
<div style="width:350px;"><gcse:search></gcse:search></div>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900