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("你要找的字符串没有出现在该网站!")  

执行结果:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/dahaiyudong/article/details/80666446