LuanRT / google-this

A simple yet powerful module to retrieve organic search results and much more from Google.
https://www.npmjs.com/package/googlethis
MIT License
320 stars 77 forks source link

Add SELECTORS override option, fix current TITLE selector #67

Closed timsu closed 6 months ago

timsu commented 10 months ago

Description

Adds the ability to override Constants.SELECTORS if passed in via search options. This should alleviate some of the urgency to update npm every time Google changes things. It does change Constants.SELECTORS permanently, but I can't think of a reason why you wouldn't want that.

Also fixes the current TITLE selector so all tests pass (from https://github.com/LuanRT/google-this/issues/66)

Type of change

Please delete options that are not relevant.

Checklist:

download13 commented 9 months ago

It looks like the selectors may have changed again already. I've got a thought on how it might be made more reliable in the long-term over at #69 if you want to take a look.

LuanRT commented 9 months ago

@download13 Yes indeed they have. I'm currently preparing to refactor this library and kind of want to get rid of the selectors mess, it used to work fine but now it's becoming annoying (in fact, the old selectors used in earlier versions of the library kept working for an entire year, but now the updated ones barely last 1 month :/).

timsu commented 9 months ago

Cool, both are good ideas.

I only need the organic search results, so the structure approach seems more appealing to me. Just playing around with Google now:

> results = Array.from(document.querySelectorAll("h1")).find(n => n.innerText == "Search Results")
<h1 class=​"bNg8Rb OhScic zsYMMe BBwThe" style=​"clip:​rect(1px,1px,1px,1px)​;​height:​1px;​overflow:​hidden;​position:​absolute;​white-space:​nowrap;​width:​1px;​z-index:​-1000;​-webkit-user-select:​none">​Search Results​</h1>​

> Array.from(results.parentElement.querySelectorAll("h3")).map(a => a.innerText)
(9) ['Test Definition & Meaning - Merriam-Webster', 'Speedtest by Ookla - The Global Broadband Speed Test', 'TEST | Home', 'TEST Definition & Usage Examples', 'Self-Testing At Home or Anywhere', 'COVID-19 Testing: What You Need to Know', 'TEST | definition in the Cambridge English Dictionary', 'Fast.com: Internet Speed Test', 'Test']0: "Test Definition & Meaning - Merriam-Webster"1: "Speedtest by Ookla - The Global Broadband Speed Test"2: "TEST | Home"3: "TEST Definition & Usage Examples"4: "Self-Testing At Home or Anywhere"5: "COVID-19 Testing: What You Need to Know"6: "TEST | definition in the Cambridge English Dictionary"7: "Fast.com: Internet Speed Test"8: "Test"length: 9[[Prototype]]: Array(0)

> Array.from(results.parentElement.querySelectorAll("*[style='-webkit-line-clamp:2']")).map(a => a.innerText)
...

Perhaps it might be a good temporary solution to use non-class selectors until the refactor happens.

cdwmhcc commented 9 months ago

any update?

github-actions[bot] commented 6 months ago

This PR has been automatically marked as stale because it has not had recent activity. Remove the stale label or comment or this will be closed in 2 days