小编Pab*_*blo的帖子

如何在没有路由的情况下在 python flask 中执行正常函数并使用路由返回此过程的结果?

该应用程序正在加载“links_submit.html”,其中有一个字段,您可以在其中编写链接,例如 (www.google.com) 并提交它,然后该应用程序会将此 URL 作为 HTTP Post 接收并重定向到另一个页面“post_response.html”,其中包含一个简单的 html,用于反馈“Ok”一词。然后我想用这个链接做一个过程(抓取谷歌并搜索特定的东西),完成这个过程后,自动从“post_reponse.html”重定向到另一个页面,以显示我从谷歌中提取的结果。现在我不确定如何在烧瓶上对我的应用程序说:“好的,现在让我们使用正常功能(不是路由),例如:

def loadpage(link_sent_by_the_http post):
   res = requests.get('www.google.com')
Run Code Online (Sandbox Code Playgroud)

想象一下,在加载页面后,我还在 google 上提取了一些 html 标签,在完成此过程后,我想将带有“ok”的页面“post_respose.html”重定向到一个新的 html 页面,其中包含从 google 中提取的 html 标签。请注意,我知道如何加载页面 google 并提取我想要的内容,但我不知道如何在 Flask 中间插入此函数/进程,然后从带有“ok”的普通 html 重定向到一条新路由我提取的结果。

import requests
from flask import Flask, render_template, request, url_for

app = Flask(__name__)

@app.route('/test')
def form():
   return render_template('links_submit.html')

@app.route('/links/', methods=['POST'])
def links():
    links=request.form['links']
    return render_template('post_response.html')

Intern Process (Load the received link > Extract what I want)
and then redirect the "post_response.html" to another "html" which will
contain the results …
Run Code Online (Sandbox Code Playgroud)

python flask

5
推荐指数
0
解决办法
5908
查看次数

如何使用 Scrapy - XMLfeedspider 从 XML 页面中提取 url、加载它们并提取其中的信息?

我正在使用 Scrapy 中的 XMLfeedspider 从页面 xml 中提取信息。我试图仅提取此页面上标签“loc”内的链接并加载它们,但阻止页面重定向,然后将其发送到最后一个解析节点,该解析节点将从该页面收集信息。问题是我不确定是否可以在“def star_urls”上加载这些页面,或者我是否需要使用 parse_node 并重定向到另一个解析来提取我需要的信息,但即使我尝试这样做,我'我不确定如何仅从 xml 页面中提取链接,而不是所有 loc 标记。

继续我的想法:

这个想法应该是加载这个 xml 页面<loc>从中提取标签内的链接,如下所示:

https://www.gotdatjuice.com/track-2913133-sk-invitational-ft-sadat-x-lylit-all-one-cdq.html https://www.gotdatjuice.com/track-2913131-sk-invitational -ft-mop-we-dont-stop-cdq.html

最后加载每个页面并提取标题和网址。

有任何想法吗?

找到下面我的代码:

from scrapy.loader import ItemLoader
from scrapy.spiders import XMLFeedSpider
from scrapy.http import Request
from testando.items import CatalogueItem

class TestSpider(XMLFeedSpider):

    name = "test"
    allowed_domains = ["gotdajuice.ie"]
    start_urls = [      
        'https://www.gotdatjuice.com/sitemap.xml'
    ]   

    namespaces = [('n', 'http://www.sitemaps.org/schemas/sitemap/0.9')]
    itertag = 'n:loc'
    iterator = 'xml'


    name_path = ".//div[@class='song-name']/h1/text()"


    def start_request(self):
      urls = node.xpath(".//loc/text()").extract()
      for url in urls:
          yield …
Run Code Online (Sandbox Code Playgroud)

python xml scrapy

1
推荐指数
1
解决办法
1538
查看次数

标签 统计

python ×2

flask ×1

scrapy ×1

xml ×1