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

  • Home
  • SEARCH
  • 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 1099295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:42:53+00:00 2026-05-17T00:42:53+00:00

i am trying to grab links from the Google search page. i am using

  • 0

i am trying to grab links from the Google search page. i am using the be below xpath to

//div[@id='ires']/ol[@id='rso']/li/h3/a/@href

grab the links. xPather evaluates it and gives the result. But when i use it with my php it doesn’t show any result. Can someone please tell me what I am doing wrong? There is nothing wrong with the cURL.

below is my code

$dom = new DOMDocument();
@$dom->loadHTML($result);

$xpath=new DOMXPath($dom);
$elements = $xpath->evaluate("//div[@id='ires']/ol[@id='rso']/li/h3/a");

foreach ($elements as $element)
{
   $link  = $element->getElementsByTagName("href")->item(0)->nodeValue;

   echo $link."<br>";
}

Sample Html provided by Robert Pitt

<li class="g w0">
    <h3 class="r">
       <a href="" class="l"><em>LINK</em></a>
    </h3>
    <button class="ws" title=""></button>
    <div class="s">
        META
    </div>
</li>
  • 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-05-17T00:42:54+00:00Added an answer on May 17, 2026 at 12:42 am

    You can make life simpler by using the original XPath expression that you quoted:

    //div[@id='ires']/ol[@id='rso']/li/h3/a/@href
    

    Then, loop over the matching attributes like:

    $hrefs = $xpath->evaluate(...);
    foreach ($hrefs as $href) {
        echo $href->value . "<br>";
    }
    

    Be sure to check whether any attributes were matched (var_dump($hrefs->length) would suffice).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I'm trying to grab an EXE from CNet's Download.com So i created web
I'm trying to grab thousands of invoices (and other stuff) from a text file
I'm trying to grab all NA phone numbers from a CSV file. The numbers
Trying to grab the two $ values and the X value from this string
I am trying to grab source code of pages using proxies. It works up
I'm behind a proxy, and I'm trying to grab a jar from my local
I'm trying to get the following regular expression to grab only the letters from
Ok, I am trying to grab some data off a internal web site that
Conceptually, I am trying to grab 8 separate survey scores for every user in
I'm working on a PHP application that links into the Protx VSP Direct payment

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.