Xpath on Google Local Path Help Requested

Hello,

I am using this Xpath to pull Google Local Pack results.

//div[1]/div[*]/div/div/a[2]

It mostly works great with a few exceptions :frowning:
For example:

when using the formula:
=IF(M25="","",Dump(XPathOnUrl(R25,$AO$1,"href",HttpSettings(TRUE,,,"3000|6000|Host"),"text"),TRUE))

if $AO$1 is always:
//div[1]/div[*]/div/div/a[2]

and if M25 is, for example, any of these:
http://www.google.com/search?pws=0&gl=EN&q=Nashville Automobile Accidents Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville Bicycle Accidents Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville Bus Accidents Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville Car Accidents Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville Broken Bones Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville Car Accidents On I 40 I 65 Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville Driver Texting Distraction Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville Facial Injuries Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville How to handle the aftermath of a car accident Lawyer&num=10
http://www.google.com/search?pws=0&gl=EN&q=Nashville Internal Injuries Lawyer&num=10

I get good result urls.

but sometimes I don't :frowning:

http://www.google.com/search?pws=0&gl=EN&q=Nashville DUI Accidents Injuries Lawyer&num=10 generates 4 resutls versus the standard 3 map pack resutls. The odd result (intead of a normal url) is: /aclk?sa=l&ai=DChcSEwi1i6CzgqfVAhUMF4EKHR9GCeEYABAFGgJ5dw&sig=AOD64_0t0y0OuSRq9Xkv9JqRuupx9IKEOw&q=&ctype=99&ved=0ahUKEwigyZuzgqfVAhUJ4yYKHfOmDLsQhKwBCFI&adurl=

another example is:
http://www.google.com/search?pws=0&gl=EN&q=Nashville What is the difference between compensatory and punitive damages Lawyer&num=10
which generates:
/search?pws=0&gl=EN&tbm=bks&q=inauthor:%22Henry+Philip+Farnham%22&sa=X&ved=0ahUKEwiurpikg6fVAhVHOCYKHaicDrMQ9AgIRDAG

  • 3 good urls

and another is:
http://www.google.com/search?pws=0&gl=EN&q=Nashville Nashville Personal Injury Office Lawyer&num=10
which generates:
/aclk?sa=l&ai=DChcSEwiQ8ZHAgqfVAhWRPIEKHWUDCH8YABAOGgJ5dw&sig=AOD64_07krbeJbY9Vqs8VfFXWRorQozbow&q=&ctype=99&ved=0ahUKEwjiko7AgqfVAhWFQSYKHQmCBmEQhKwBCFQ&adurl=

  • 3 good urls.

any insight/ help on the proper xpath to generate ONLY the 3 normal pack results would be appreciated.

Thanks!
Chris

I mistakenly referenced M25. I meant R25.

Hi Chris,

It would help if you could be more specific about exactly what you need to extract and supply a specific url. Do you mean these three links?

Thanks very much for the quick reply.

here is an example. This search
http://www.google.com/search?pws=0&gl=EN&q=Nashville Automobile Accidents Lawyer&num=10
generates the 3 pack (red boxed)
https://www.screencast.com/t/apisdd9z085

The formula to generate the desired results is;

=Dump(XPathOnUrl("http://www.google.com/search?pws=0&gl=EN&q=Nashville Automobile Accidents Lawyer&num=10","//div[1]/div[*]/div/div/a[2]","href",HttpSettings(TRUE,,,"3000|6000|Host"),"text"),TRUE)

I've tried this successfully with the list of "for example urls" previously posted, where it lists 3 domains scraped from the Google 3-pack.

BUT... when trying the same formula using the urls from the list under "sometimes I don't :(" I get the non domain result in my example.

does that help clarify?
any insight/help would be appreciated.
Thanks!
Chris

The URL you provided generates the page in the screen dump in my previous post. Google doesn't return the same results for identical search URLs because of your location etc. This might also be affected by the header settings and they may be changed when sending a request via SeoTools.

This makes it very hard to test xpaths based on your urls and it might also be the reason you have random success.

Hi again,

if you paste this...
http://www.google.com/search?pws=0&gl=EN&q=Nashville Automobile Accidents Lawyer&num=10
It's the same as this...
http://www.google.com/search?pws=0&gl=EN&q=Nashville+Automobile+Accidents+Lawyer&num=10

because of the way the forum creates the link you are not getting the whole url.

you are only navigating to...
http://www.google.com/search?pws=0&gl=EN&q=Nashville

you should be using http://www.google.com/search?pws=0&gl=EN&q=Nashville+Automobile+Accidents+Lawyer&num=10

Does that help?

Yes, that works. Will take a look at it and see if i can find a reliable way of scraping the location info.

Hi Victor - Just checking in on this. Were you able to find anything that could help?
Any insights would be appreciated.
Thanks
Chris

Hi Chris,

Sorry for a late response. How about this:

Your xpaths didn't work for me and had issues finding an isolated path with titles which were not auto-generated. However, this seems to do the trick!