本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理
本文章来自腾讯云 作者:python学习教程
猜数字(又称 Bulls and Cows )是一种古老的的密码破译类益智类小游戏,起源于20世纪中期,一般由两个人或多人玩,也可以由一个人和电脑玩。
源码展示:
import webbrowser as web
import re
import urllib
import time
import os
def spider(url,urlpattern):
urls=getURLs(url,urlpattern)
for url in urls:
visitURL(url)
def visitURL(url):
url=url[:-1] #remove the " at the end of the string
print(url)
#print("\n")
web.open(url,1,False)
time.sleep(5)
def getURLs(url,urlpattern):
urls=[]
response=urllib.urlopen(url)
html=response.read()
pattern=re.compile(urlpattern)
urls=pattern.findall(html)
urls=list(set(urls))
return urls
if __name__=="__main__":
urls={
"这里填写你blog的地址"
}
for i in range(1,10):
for url,urlpattern in urls.items():
spider(url,urlpattern)
print("Blogs has been refreshed for ", i, " times")
os.system("taskkill /F /IM chrome.exe")