小编tha*_*nen的帖子

BeautifulSoup 获取列表的 href - 需要简化脚本 - 替换多处理

我有以下汤:

接下来...我想从中提取href,“some_url”

我想提取 href,“some_url”

以及此页面上列出的页面的完整列表:https://www.catholic-hierarchy.org/diocese/laa.html

注意:有很多子页面的链接:我需要解析它们。目前:获取所有数据:-dioceses -Urls -description -contact-data -etc。等。

下面的示例将获取教区的所有 URL,获取有关每个教区的一些信息并创建最终的数据帧。为了加速进程 multiprocessing.Pool 的使用:

但是等等:如何在没有多处理支持的情况下让这个刮刀运行!?我想在Colab中运行它- 因此需要摆脱多处理功能。

如何实现这一点..!?

import requests
from bs4 import BeautifulSoup
from multiprocessing import Pool


def get_dioceses_urls(section_url):
    dioceses_urls = set()

    while True:
        print(section_url)

        soup = BeautifulSoup(
            requests.get(section_url, headers=headers).content, "lxml"
        )
        for a in soup.select('ul a[href^="d"]'):
            dioceses_urls.add(
                "https://www.catholic-hierarchy.org/diocese/" + a["href"]
            )

        # is there Next Page button?
        next_page = soup.select_one('a:has(img[alt="[Next Page]"])')
        if next_page:
            section_url = (
                "https://www.catholic-hierarchy.org/diocese/"
                + next_page["href"]
            )
        else:
            break

    return dioceses_urls …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup html-parsing web-scraping

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

停止脚本的 WP-选项:此处 Google-Maps API:wp_dequeue 或 wp_deregister 脚本?或者...甚至删除?

如何使用 wp_dequeue 来阻止脚本在 WordPress 中加载: ...或者这里还有更多选项,我们可以使用。

\n

背景:

\n

首先:我们正在谈论这个网站:https://www.job-starter.com \n这个网站运行:wordpress 6.3.1\n插件:wp-job-manager\n主题:jobify-theme by astoundify.com -请参阅https://astoundify.com/products/jobify/

\n

注意:此主题使用 Google 地图 - 我不想在我的网站上运行此主题 - 因为我不想因 API 调用而遇到法律问题:

\n

(主题的)开发人员说 - 我网站上的 Google_Map_API 如下:

\n
js?v=3&libraries=geometry%2Cplaces&language=en&ver=6.3. \ncommon.js \nutil.js\n
Run Code Online (Sandbox Code Playgroud)\n

主题作者正在加载 Google Maps API,但网站上并未使用它,因此我想在子主题的functions.php 中将其出列。他们不提供在主题设置中简单地禁用它的选项。\n问题:有人介意帮我提供一些关于我们这里的选项的想法吗:

\n
    \n
  • A。我们可以在家长主题中将其注释掉或者
  • \n
  • b. 在子主题中将其出列?以及有什么选择
  • \n
  • C。注销它,甚至更多......只是为了
  • \n
  • d. 去掉它
  • \n
\n

所以这里有很多选项: wp_dequeue 代码

\n

问题:

\n

在父主题中将其注释掉或在子主题中将其出列在技术上不是更有效吗?我知道修改父主题代码的固有问题。\n关于选项...

\n

我们可以与

\n
(\'bazien-google-maps\', \'https://maps.googleapis.com/maps/api/js?kewp_enqueue_script(\'bazien-google-maps\', \'https://maps.googleapis.com/maps/api/js?ke\n
Run Code Online (Sandbox Code Playgroud)\n

但是等等: 这不是最好的 WordPress 方式吗,我们需要在子主题中取消注册它。为此,请使用以下命令:

\n
wp_deregister_script( \'bazien-google-maps\' …
Run Code Online (Sandbox Code Playgroud)

php wordpress

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