以下是一个 Python 程序代码,可以检查网页中是否存在指定的关键字:

import requests

# 要检查的关键字
keywords = ['python', 'web', 'programming']

# 要检查的网页
url = 'https://www.example.com'

# 获取网页内容
response = requests.get(url)
content = response.content.decode('utf-8')

# 检查关键字是否存在
for keyword in keywords:
    if keyword in content:
        print(f'关键字 '{keyword}' 存在于网页中。')
    else:
        print(f'关键字 '{keyword}' 不存在于网页中。')

该程序使用 requests 库获取网页内容,然后遍历关键字列表,检查每个关键字是否出现在网页内容中。如果出现则输出提示信息。

Python 代码检查网页关键字

原文地址: http://www.cveoy.top/t/topic/oArI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录