可以使用Python中的requests和BeautifulSoup库来实现这个任务。下面是示例代码:
import requests
from bs4 import BeautifulSoup
# 网页地址
url = 'https://cn.bing.com'
# 要查找的单词列表
words = ['必应', '搜索', '新闻']
# 获取网页内容
response = requests.get(url)
html = response.text
# 解析网页内容
soup = BeautifulSoup(html, 'html.parser')
# 搜索包含指定单词的元素
for word in words:
result = soup.find(text=word)
if result:
print(f'{word} found on {url}')
else:
print(f'{word} not found on {url}')
这个脚本将搜索包含在words
列表中的单词,并输出它们是否在给定的网页上找到。可以随意更改url
和words
列表,以适应任何网页和单词列表。