練習一下...
import requests
import re
url='http://www.mcut.edu.tw'
htmlfile=requests.get(url)
if htmlfile.status_code == requests.codes.ok:
print("ok")
print("html size=",len(htmlfile.text))
pattern=input("search pattern:")
if pattern in htmlfile.text:
print("search %s ok" %pattern)
else:
print("search %s fail" %pattern)
name=re.findall(pattern,htmlfile.text)
if name !=None:
print("%s find %d" %(pattern,len(name)))
else:
print("%s find 0" % pattern)
else:
print("ng")
沒有留言:
張貼留言