Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9242043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:29:53+00:00 2026-06-18T08:29:53+00:00

I would like to extract links when you make a google search with a

  • 0

I would like to extract links when you make a google search with a specific keyword.
I know that an API already exists but I want to create my own script.
Currently, I can extract links but my regex is not very good.

#  /url?q=http://wikipedia.org/wiki/World_Wide_Web&sa=U&ei=naEHUbDoLITQ0QXWwIGoCw&ved=0CB8QFjAA&usg=AFQjCNEn84GVN2VHpfEVjnMm5FG_p8YjgQ

I don’t know exactly how we can keep only the real url.
So, if you have an idea.
Thanks

$key = "test"; 
if ($kw = $key){
    $pagenum = 0;               
    $googlefrurl = "http://www.google.com/search?q=" . urlencode($kw) . "&start=$pagenum";

    while($pagenum <= 0){
        $result= file_get_contents($googlefrurl); 
        preg_match_all('<a href="(.*?)">si', $result, $matches);
        $i = 0;         
        $n = count($matches[1]);        
        $pagenum++;         
        $pagenum2 = $pagenum.'0'; 
        $googlefrurl = "http://www.google.com/search?q=" . urlencode($kw) .
            "&start=$pagenum2&safe=off&pwst=1&filter=0";

        while($i <= $n){
            $u++;
        } 
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:29:54+00:00Added an answer on June 18, 2026 at 8:29 am

    You need a Google API Key to make searchs and then use the custom search REST API
    https://developers.google.com/custom-search/v1/using_rest

    Which return a JSON with the results and everything you need
    For example, the request (quick copy from docs):

    GET https://www.googleapis.com/customsearch/v1?
    key=INSERT-YOUR-KEY&cx=013036536707430787589:_pqjad5hr1a&q=flowers&alt=json
    

    Returns

    200 OK
    
    {
     "kind": "customsearch#search",
     "url": {
      "type": "application/json",
      "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&nsc={nsc?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
     },
     "queries": {
      "nextPage": [
       {
        "title": "Google Custom Search - flowers",
        "totalResults": 10300000,
        "searchTerms": "flowers",
        "count": 10,
        "startIndex": 11,
        "inputEncoding": "utf8",
        "outputEncoding": "utf8",
        "cx": "013036536707430787589:_pqjad5hr1a"
       }
      ],
      "request": [
       {
        "title": "Google Custom Search - flowers",
        "totalResults": 10300000,
        "searchTerms": "flowers",
        "count": 10,
        "startIndex": 1,
        "inputEncoding": "utf8",
        "outputEncoding": "utf8",
        "cx": "013036536707430787589:_pqjad5hr1a"
       }
      ]
     },
     "context": {
      "title": "Custom Search"
     },
     "items": [
     {
       "kind": "customsearch#result",
       "title": "Flower - Wikipedia, the free encyclopedia",
       "htmlTitle": "\u003cb\u003eFlower\u003c/b\u003e - Wikipedia, the free
       encyclopedia",
       "link": "http://en.wikipedia.org/wiki/Flower",
       "displayLink": "en.wikipedia.org",
       "snippet": "A flower, sometimes known as a bloom or blossom, is the reproductive structure found in flowering plants (plants of the division Magnoliophyta, ...",
       "htmlSnippet": "A \u003cb\u003eflower\u003c/b\u003e, sometimes known as a bloom or blossom, is the reproductive structure \u003cbr\u003e  found in flowering plants (plants of the division Magnoliophyta, \u003cb\u003e... \u003c/b\u003e",
       "pagemap": {
        "RTO": [
         {
          "format": "image",
          "group_impression_tag": "prbx_kr_rto_term_enc",
          "Opt::max_rank_top": "0",
          "Opt::threshold_override": "3",
          "Opt::disallow_same_domain": "1",
          "Output::title": "\u003cb\u003eFlower\u003c/b\u003e",
          "Output::want_title_on_right": "true",
          "Output::num_lines1": "3",
          "Output::text1": "꽃은 식물 에서 씨 를 만들어 번식 기능을 수행하는 생식 기관 을 말한다. 꽃을 형태학적으로 관찰하여 최초로 총괄한 사람은 식물계를 24강으로 분류한 린네 였다. 그 후 꽃은 식물분류학상중요한 기준이 되었다.",
          "Output::gray1b": "- 위키백과",
          "Output::no_clip1b": "true",
          "UrlOutput::url2": "http://en.wikipedia.org/wiki/Flower",
          "Output::link2": "위키백과 (영문)",
          "Output::text2b": "   ",
          "UrlOutput::url2c": "http://ko.wikipedia.org/wiki/꽃",
          "Output::link2c": "위키백과",
          "result_group_header": "백과사전",
          "Output::image_url": "http://www.gstatic.com/richsnippets/b/fcb6ee50e488743f.jpg",
          "image_size": "80x80",
          "Output::inline_image_width": "80",
          "Output::inline_image_height": "80",
          "Output::image_border": "1"
         }
        ]
       }
      },
      ...
     ]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Nokogiri to extract links from a page but I would like to
I would like to extract and construct some strings after identifying a substring that
I would like to extract text from an html document keeping the links inside
I would like to extract all img tags that are within an anchor tag
I would like to extract a color histogram out of a BufferedImage (Java). I
I would like to extract portion of a text using a regular expression. So
I would like to extract items from this sample html, more specificly, i would
I would like to extract the GPS EXIF tag from pictures using php. I'm
I would like to extract a value or its inverse from database. I would
I would like to extract only tar.gz from the following strings. /root/abc/xzy/file_tar_src-5.2.8.23.tar.gz or /root/abc/xyz/file_tar_src-5.2.tar.gz

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.