如果只是要找出某一个或某些单词、字符串是否出现在某个网页中,只要使用in就可以了。
见下面例子:
import requests
url = "https://www.baidu.com/s?wd=csdn%20%20abvedu&tn=95407960_s_hao_pg&ie=utf-8&ssl_sample=normal"
html = requests.get(url).text
print(html)
str = input("请输入要查找的字符串:")
if str in html:
print("你找到了字符串:{}".format(str))
else:
print("你要找的字符串没有出现在该网站!")
执行结果:
<html>
<head>