繁体   English   中英

使用Python(Flask)从qwant API接收数据

[英]Recieving data from qwant API with python (Flask)

据我所知,我正在使用此“ 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行第1列(字符0)

而且我似乎找不到解决方法。

您可以解决此问题,但是使用这种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 API获取数据。 这样可以解决您的问题。 我无法解释为什么我们需要添加这些参数,因为Qwant API没有记录且不是开源的。 我们可以在https://github.com/asciimoo/searx/blob/master/searx/engines/qwant.py (如https://github.com/asciimoo/searx/issues/ 1365年表示,今年夏天Qwant API发生了变化。)

在请求之前添加用户代理,

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM