Du Mingzhe
commited on
Commit
·
088c177
1
Parent(s):
620c713
Update
Browse files- components.py +19 -15
components.py
CHANGED
@@ -145,20 +145,24 @@ class WebSearcher(object):
|
|
145 |
return response_json
|
146 |
|
147 |
def query_bing(self, query):
|
148 |
-
headers = {"Ocp-Apim-Subscription-Key": self.bing_api_key}
|
149 |
-
params = {"q": query, "textDecorations": True, "textFormat": "HTML"}
|
150 |
-
response = requests.get("https://api.bing.microsoft.com/v7.0/search", headers=headers, params=params)
|
151 |
-
response.raise_for_status()
|
152 |
-
search_results = response.json()
|
153 |
-
|
154 |
filter_results = list()
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
}]
|
163 |
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
return response_json
|
146 |
|
147 |
def query_bing(self, query):
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
filter_results = list()
|
149 |
+
try:
|
150 |
+
headers = {"Ocp-Apim-Subscription-Key": self.bing_api_key}
|
151 |
+
params = {"q": query, "textDecorations": True, "textFormat": "HTML"}
|
152 |
+
response = requests.get("https://api.bing.microsoft.com/v7.0/search", headers=headers, params=params)
|
153 |
+
response.raise_for_status()
|
154 |
+
search_results = response.json()
|
155 |
+
print(search_results)
|
|
|
156 |
|
157 |
+
for result in search_results['webPages']['value']:
|
158 |
+
filter_results += [{
|
159 |
+
'name': result['name'],
|
160 |
+
'url': result['url'],
|
161 |
+
'snippet': result['snippet'],
|
162 |
+
'dateLastCrawled': result['dateLastCrawled'],
|
163 |
+
}]
|
164 |
+
|
165 |
+
return filter_results
|
166 |
+
except Exception as e:
|
167 |
+
print(f"Error: {e}")
|
168 |
+
return filter_results
|