Skip to content
Advertisement

Get Bing search results in Python

I am trying to make a chatbot that can get Bing search results using Python. I’ve tried many websites, but they all use old Python 2 code or Google. I am currently in China and cannot access YouTube, Google, or anything else related to Google (Can’t use Azure and Microsoft Docs either). I want the results to be like this:

JavaScript

Code

JavaScript

And it gives me

JavaScript

Any help would be greatly appreciated (I’m using Python 3.6.9 on Ubuntu)

Advertisement

Answer

Actually, code you’ve written working properly, problem is in HTTP request headers. By default urllib use Python-urllib/{version} as User-Agent header value, which makes easy for website to recognize your request as automatically generated. To avoid this, you should use custom value which can be achieved passing Request object as first parameter of urlopen():

JavaScript

P.S. Take a look on comment left by @edd under your question.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement