Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic search does not work at all #155

Open
braindevices opened this issue Jan 25, 2022 · 3 comments
Open

basic search does not work at all #155

braindevices opened this issue Jan 25, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@braindevices
Copy link

Describe the bug

ENGINE FAILURE: Bing
raise NoResultsOrTrafficError(
search_engine_parser.core.exceptions.NoResultsOrTrafficError: The result parsing was unsuccessful. It is either your query could not be found or it was flagged as unusual traffic

I tried the example from readme page. gsearch and bsearch all raise the same error.

the ysearch throw a different error:

line 61, in parse_single_result
    rdict["descriptions"] = desc.text
AttributeError: 'NoneType' object has no attribute 'text'
@braindevices braindevices added the bug Something isn't working label Jan 25, 2022
@braindevices
Copy link
Author

my ip is not blocked by any of those search engines. I try to debug a little bit by output the url and html with following code:

from search_engine_parser.core.engines.google import Search as GoogleSearch

gsearch = GoogleSearch()
search_args = ('python google search api', 1)
gsearch.search(*search_args, cache=False, hl="en")

The url is https://www.google.com/search?start=0&q=python+google+search+api&gbv=1&hl=en
And I found the resulting html from get_source() saying:

Before you continue to Google Search
Google uses cookies and data to:

    Deliver and maintain services, like tracking outages and protecting against spam, fraud, and abuse
    Measure audience engagement and site statistics to understand how our services are used

If you agree, we’ll also use cookies and data to:

    Improve the quality of our services and develop new ones
    Deliver and measure the effectiveness of ads
    Show personalized content, depending on your settings
    Show personalized or generic ads, depending on your settings, on Google and across the web

For non-personalized content and ads, what you see may be influenced by things like the content you’re currently viewing and your location (ad serving is based on general location). Personalized content and ads can be based on those things and your activity like Google searches and videos you watch on YouTube. Personalized content and ads include things like more relevant results and recommendations, a customized YouTube homepage, and ads that are tailored to your interests.

Click “Customize” to review options, including controls to reject the use of cookies for personalization and information about browser-level controls to reject some or all cookies for other uses. You can also visit g.co/privacytools anytime.

So it seems like you need to confirm something and save some cookie before you could go on.

@braindevices
Copy link
Author

bingsearch only works once per 5 to 8 trials. no idea why though.

@neithere
Copy link
Contributor

neithere commented Aug 26, 2022

Looks like the consent cookie should be set, e.g. like this: https://stackoverflow.com/a/70560365/68097

Unfortunately the lib doesn't seem to be configurable in this aspect. The cookies argument should be passed to aiohttp.ClientSession() in CacheHandler.get_source(): https://github.com/bisohns/search-engine-parser/blob/master/search_engine_parser/core/utils.py#L78

FYI, I've added a very crude workaround here: a537f4e
Obviously a proper implementation should add an engine-dependent set of default cookies or something in this vein.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants