0

I have the following URL https://www.bing.com/search?q=site%3Awww.linkedin.com%20Employnet%2C+Inc.%20Monterey%20CA%20NOT%20jobs%20NOT%20pulse%20NOT%20profinder%%20NOT%20dir%20NOT%20company%20intitle%3AEmploynet%2C+Inc.

when I go to the URL the search becomes like this site:www.linkedin.com Employnet, Inc. Monterey CA NOT jobs NOT pulse NOT profinder% NOT dir NOT company intitle:Employnet, Inc.

Here is my code:

url="https://www.bing.com/search?q=site%3Awww.linkedin.com%20Employnet%2C+Inc.%20Monterey%20CA%20NOT%20jobs%20NOT%20pulse%20NOT%20profinder%%20NOT%20dir%20NOT%20company%20intitle%3AEmploynet%2C+Inc."
url=url.replace("%3A",":").replace("%20"," ").replace("%2C+",", ")
search=re.search('.*?q=(.*)',url).groups()[0]

I Feel like this a poor method of doing it, is there a more technical way for proper encoding

  • Not an answer to your question. Why not [Bing Search API](https://learn.microsoft.com/en-us/azure/cognitive-services/bing-web-search/web-sdk-python-quickstart)? – Unni Apr 30 '19 at 15:53
  • @Unni exactly what I am trying do but the search API required it to as in the "box" –  Apr 30 '19 at 15:55
  • Related, maybe dupe: [URL encoding in python](https://stackoverflow.com/q/8905864/674039) – wim Apr 30 '19 at 16:05

1 Answers1

0

Using Python 3:

>>> import urllib.parse
>>> url="https://www.bing.com/search?q=site%3Awww.linkedin.com%20Employnet%2C+Inc.%20Monterey%20CA%20NOT%20jobs%20NOT%20pulse%20NOT%20profinder%%20NOT%20dir%20NOT%20company%20intitle%3AEmploynet%2C+Inc."
>>> urllib.parse.unquote_plus(url)
'https://www.bing.com/search?q=site:www.linkedin.com Employnet, Inc. Monterey CA NOT jobs NOT pulse NOT profinder% NOT dir NOT company intitle:Employnet, Inc.'

Or extract the query and unquote_plus it:

>>> urllib.parse.unquote_plus(urllib.parse.urlsplit(url).query[2:])
'site:www.linkedin.com Employnet, Inc. Monterey CA NOT jobs NOT pulse NOT profinder% NOT dir NOT company intitle:Employnet, Inc.'
ForceBru
  • 43,482
  • 10
  • 63
  • 98