Returns a list of results from Yahoo for the given query. - type : SEARCH, IMAGE or NEWS, - start: maximum 1000 results => start 1-100 with count=10, 1000/count, - count: maximum 50, or 35 for images. There is no daily limit, however Yahoo BOSS is a p
(self, query, type=SEARCH, start=1, count=10, sort=RELEVANCY, size=None, cached=True, **kwargs)
| 1138 | return url |
| 1139 | |
| 1140 | def search(self, query, type=SEARCH, start=1, count=10, sort=RELEVANCY, size=None, cached=True, **kwargs): |
| 1141 | """ Returns a list of results from Yahoo for the given query. |
| 1142 | - type : SEARCH, IMAGE or NEWS, |
| 1143 | - start: maximum 1000 results => start 1-100 with count=10, 1000/count, |
| 1144 | - count: maximum 50, or 35 for images. |
| 1145 | There is no daily limit, however Yahoo BOSS is a paid service. |
| 1146 | """ |
| 1147 | if type not in (SEARCH, IMAGE, NEWS): |
| 1148 | raise SearchEngineTypeError |
| 1149 | if type == SEARCH: |
| 1150 | url = YAHOO + "web" |
| 1151 | if type == IMAGE: |
| 1152 | url = YAHOO + "images" |
| 1153 | if type == NEWS: |
| 1154 | url = YAHOO + "news" |
| 1155 | if not query or count < 1 or start < 1 or start > 1000 / count: |
| 1156 | return Results(YAHOO, query, type) |
| 1157 | # 1) Create request URL. |
| 1158 | url = URL(url, method=GET, query={ |
| 1159 | "q": query, |
| 1160 | "start": 1 + (start-1) * count, |
| 1161 | "count": min(count, type==IMAGE and 35 or 50), |
| 1162 | "format": "json" |
| 1163 | }) |
| 1164 | # 2) Restrict language. |
| 1165 | if self.language is not None: |
| 1166 | market = locale.market(self.language) |
| 1167 | if market: |
| 1168 | url.query["market"] = market.lower() |
| 1169 | # 3) Authenticate. |
| 1170 | url = self._authenticate(url) |
| 1171 | # 4) Parse JSON response. |
| 1172 | kwargs.setdefault("unicode", True) |
| 1173 | kwargs.setdefault("throttle", self.throttle) |
| 1174 | try: |
| 1175 | data = url.download(cached=cached, **kwargs) |
| 1176 | except HTTP401Authentication: |
| 1177 | raise HTTP401Authentication, "Yahoo %s API is a paid service" % type |
| 1178 | except HTTP403Forbidden: |
| 1179 | raise SearchEngineLimitError |
| 1180 | data = json.loads(data) |
| 1181 | data = data.get("bossresponse") or {} |
| 1182 | data = data.get({SEARCH:"web", IMAGE:"images", NEWS:"news"}[type], {}) |
| 1183 | results = Results(YAHOO, query, type) |
| 1184 | results.total = int(data.get("totalresults") or 0) |
| 1185 | for x in data.get("results", []): |
| 1186 | r = Result(url=None) |
| 1187 | r.url = self.format(x.get("url", x.get("clickurl"))) |
| 1188 | r.title = self.format(x.get("title")) |
| 1189 | r.text = self.format(x.get("abstract")) |
| 1190 | r.date = self.format(x.get("date")) |
| 1191 | r.author = self.format(x.get("source")) |
| 1192 | r.language = self.format(x.get("language") and \ |
| 1193 | x.get("language").split(" ")[0] or self.language or "") |
| 1194 | results.append(r) |
| 1195 | return results |
| 1196 | |
| 1197 | #--- BING ------------------------------------------------------------------------------------------ |
nothing calls this directly
no test coverage detected