Python:在網頁中查找字符串的一般方法--in

原文鏈接地址

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

執行結果:
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章