我正在使用这个"API",据我所知,它只是一个返回json数据的链接。链接:https://api.qwant.com/api/search/images?count=10&offset=1&q=stackoverflow
但是,当我试图访问数据时;
import requests
import json
from flask import Flask, flash, redirect, render_template, request, session, url_for, json, jsonify
@app.route("/display")
def display():
url = "https://api.qwant.com/api/search/images?count=10&offset=1&q=stackoverflow"
data = requests.get(url).json()
return data我得到以下错误;
simplejson.errors.JSONDecodeError:期望值:第1列(char 0)
我似乎找不出解决这个问题的方法。
发布于 2018-01-30 10:24:19
在请求前添加用户代理,
headers = {
'User-Agent': 'My User Agent 1.0',
}
url = "https://api.qwant.com/api/search/images?count=10&offset=1&q=stackoverflow"
data = requests.get(url, headers=headers).json()发布于 2018-09-30 14:57:02
您可以解决您的问题,但使用这种类型的URL:
https://api.qwant.com/api/search/web?count=10&offset=0&q=test&t=web&uiv=1因此,将是:
https://api.qwant.com/api/search/images?count=10&offset=0&q=stackoverflow&t=images&uiv=1为你的初步搜索。
只有这样,您才能从Qwant中获得数据。这样就解决了你的问题。我无法解释为什么我们需要添加这些参数,因为Q接触面API没有文档化,也没有开源。我们可以在https://github.com/asciimoo/searx/blob/master/searx/engines/qwant.py上找到这个答案的参考/来源(就像https://github.com/asciimoo/searx/issues/1365说的那样,Qwant在今年夏天发生了变化)。
https://stackoverflow.com/questions/48518860
复制相似问题