所以我决定在插入url时使用python goose来提取主图像。我在这里找到了很好的例子https://blog.openshift.com/day-16-goose-extractor-an-article-extractor-that-just-works/博客示例正在使用烧瓶,我试图为使用django的人制作脚本 这是我的media.py (不确定这是否有效)
media.py
import json
from goose import Goose
def extract(request):
url = request.args.get('url')
g = Goose()
article = g.extract(url=url)
resposne = {'image':article.top_image.src}
return json.dumps(resposne)
如何使用上面提到的图像并将其放在缩略图中并在index.html上显示?拜托,非常感谢任何帮助。圣诞快乐
编辑1:我尝试将下面转换为django脚本,但在我的情况下仅转换为脚本图像
from flask import Flask
from flask import jsonify
from flask import render_template
from flask import request
from goose import Goose
app = Flask(__name__)
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/api/v1/extract')
def extract():
url = request.args.get('url')
g = Goose()
article = g.extract(url=url)
response = {'title' : article.title , 'text' : article.cleaned_text[:250], 'image': article.top_image.src}
return jsonify(response)
if __name__ == "__main__":
app.run(debug=True)