gpt4 book ai didi

javascript - 如何在 flask 中解析此输出?

转载 作者:行者123 更新时间:2023-12-02 18:20:43 24 4
gpt4 key购买 nike

enter image description here

我想解析代码的描述部分。我怎样才能在金贾做到这一点?相关代码如下:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
window.onload=function (){
$("#searcher").submit(function(ev) {

/* stop form from submitting normally */

ev.preventDefault();



$.post("/searchRSS", $("#searcher").serialize(),function(o){console.log(o);document.getElementById("result").innerHTML=o;});
})};
</script>
<form id="searcher" method="post" action="#">
<input type="text" id="query" name="query" required/>
<input type="submit" value="Get Feed"/>
</form>
<div id="result">
<table>
{% for row in posts %}
<tr><td>{{ row.title }}</td></tr>
<tr><td>{{ row.date }}</td></tr>
<tr><td>{{ row.description }}</td></tr>
{% endfor %}
</table>
</div>

管理searchRSS的代码如下:

@app.route('/searchRSS',methods=['POST'])

def search_results():
feed = feedparser.parse("http://news.google.com/news?hl=en&gl=in&q="+request.form['query']+"&um=1&output=rss" )
print feed['feed']
posts = []
for i in range(0,len(feed['entries'])):
posts.append({
'title': feed['entries'][i].title,
'date': feed['entries'][i].updated,
'description': feed['entries'][i].description

})
print posts
return render_template('index.html', posts=posts)

通过解析我的意思是我只想显示相关信息而不是 HTML/CSS 标签。

最佳答案

您请求的新闻项目以 HTML 形式编码。

如果您想将它们转换为纯文本,我可以想到两种可能的选择:

  1. 删除 HTML 标记(请参阅 this question 的已接受答案,了解可能的解决方案)
  2. 使用 BeatifulSoup 等工具从 HTML 中抓取文本

关于javascript - 如何在 flask 中解析此输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18845391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com