Strange behaviour when extract url from Google Search Result Page with Javascript

Zephyr

Today I'm interested to try the following interesting piece of Javascript in Chrome:-

Array.from(document.getElementsByClassName('r')).forEach(x => console.log(x.firstChild.href))

As expected, this list out all the target url (without Google tracking) in my console. However when I try to inspect the href of the anchor, it turns out that the href is actually the Google tracking url and the target url (without Google tracking) is in the data-href instead.

I expect the value of href should be the target url (without Google tracking). May I know what's the cause of this discrepancy?

Google Search Result Page Screenshot

Zephyr

In fact, I noticed that the anchor inside the Google Search Result Page will trigger an event on mouse click which will change the orignal value of href and embed it in data-href instead.

That means as long as the anchor doesn't get clicked, the original url of the value of the href will be preserved.

My current knowledge doesn't allow me to drill down further and any more detailed or technical explanations are welcome! =)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Extract URLs from Google search result page

How to extract keywords from Google search results page URL?

Get first result from google search and its URL's with javascript

strange behaviour from loops in javascript

Strange behaviour after deleting search result object in table view

Strange behaviour in FuzzyWuzzy extract

Strange Javascript behaviour when reassigning function of a class

Python Sometimes Returns Strange Result When Reading HTML from URL

Strange behaviour of Javascript `new` from `function`

Getting Google Search Result URLs from Search String or URL

Strange output for Binary Search when result is not found

how to click a result from google search that is not on first page with selenium java

Python getting all links from a google search result page

Strange looping behaviour in javascript

Strange behaviour in JavaScript for loops

Strange behaviour of JavaScript getElementById

Strange FOR loop behaviour in Javascript

Strange behaviour in Javascript function

Strange behaviour in javascript Promise

Solr partial search, strange behaviour

Strange behaviour with Android Activity Lifecycle when connecting to Google API Client

Google Maps Javascript API LatLng Class strange behaviour

Powershell script strange behaviour when invoked from CMD/CLI

-ErrorAction strange behaviour when setting variable from COM object

Strange behaviour of GetQueuedCompletionStatus when used from thread pool worker threads

Strange behaviour when removing element from array of divs (React Hooks)

strange result when removing item from a list

Strange behaviour for Dates in Google Sheets

How to get the Image from first page when search in Google?