0

Is it possible to obtain the search query from Google search results page, given the page's URL? I've noticed that the search query is usually shown in the URL, but the format of the URL can sometimes be slightly confusing.

For example, one search results URL for the search stackoverflow is

https://www.google.com/webhp?hl=en&tab=ww#hl=en&tbo=d&sclient=psy-ab&q=stackoverflow&oq=stackoverflow&gs_l=hp.3..35i39l2j0l2.920.3338.0.3436.13.12.0.0.0.0.310.1216.10j1j0j1.12.0.les%3B..0.0...1c.1.3.psy-ab.OH00abu0aqs&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.42452523,d.dmQ&fp=8bb62755c027473d&biw=1366&bih=631

Another URL for the same search string is

https://www.google.com/search?btnG=1&pws=0&q=stackoverflow.

Would there be any way to obtain the Google search query from all types of Google search result URLs using JavaScript?

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
  • The lengthy URLs in this question are hard to read, but the question wouldn't be complete if I had omitted them, since I'm trying to extract the search string from each URL. – Anderson Green Feb 14 '13 at 20:08
  • In some cases, the search string is preceded by `oq=` or `pq` instead of `q=`, as seen here: https://www.google.com/search?btnG=1&pws=0&q=stackoverflow#hl=en&tbo=d&pws=0&sclient=psy-ab&q=stack+overflow1&oq=stack+overflow1&gs_l=serp.12..0i13i30l4.23641.23641.3.24561.1.1.0.0.0.0.87.87.1.1.0.les%3B..0.0...1c..3.psy-ab.j8-tvPh_Vqg&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.42452523,d.dmQ&fp=8bb62755c027473d&biw=1366&bih=631 – Anderson Green Feb 14 '13 at 20:10
  • *All* of the URLs you've provided have the search query as the `q` parameter. – gen_Eric Feb 14 '13 at 20:12
  • possible duplicate of [Extract keyword from Google search in Javascript](http://stackoverflow.com/questions/6045477/extract-keyword-from-google-search-in-javascript) – Anderson Green Feb 14 '13 at 20:18

1 Answers1

3

Usually the search term is the URL parameter 'q' of Google. Check here on how to do this Extract keyword from Google search in Javascript

Community
  • 1
  • 1
Mr. tk
  • 169
  • 4