Skip to content

Commit

Permalink
fix bisohns#171: find element description of the result in Bing + req…
Browse files Browse the repository at this point in the history
…uest headers
  • Loading branch information
Bentsi Magidovich committed Jul 14, 2022
1 parent 708e0ad commit 0b7ef89
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions search_engine_parser/core/engines/bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def get_params(self, query=None, page=None, offset=None, **kwargs):
params["FORM"] = "PERE"
return params

def headers(self):
base_headers = super().headers()
base_headers.update({
"cookie": f"SRCHHPGUSR=SRCHLANG=en",
"accept-language": "en-US,en;q=0.9",
})
return base_headers

def parse_soup(self, soup):
"""
Parses Bing for a search query.
Expand Down Expand Up @@ -52,8 +60,10 @@ def parse_single_result(self, single_result, return_type=ReturnType.FULL, **kwar
rdict["links"] = link

if return_type in (ReturnType.FULL, return_type.DESCRIPTION):
caption = single_result.find('div', class_='b_caption')
desc = caption.find('p')
for identifier in ({'name': 'p'}, {'name': 'div', "class_": 'b_snippetBigText'}):
desc = single_result.find(**identifier)
if desc:
break
rdict["descriptions"] = desc.text

return rdict

0 comments on commit 0b7ef89

Please sign in to comment.