如果只是要找出某一個或某些單詞、字符串是否出現在某個網頁中,只要使用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("你要找的字符串沒有出現在該網站!")
執行結果: