# pip install builtwith
# pip install python-whois
# -*- coding: utf-8 -*-
import urllib.request
import time
import re
# 寻找网站所有者
# print(whois.whois('https://blog.csdn.net/xeonmm1'))
# 下载网页
web_data = urllib.request.urlopen('https://blog.csdn.net/xeonmm1')
f = open('website_content.txt', 'w')
k = str(web_data.read().decode('utf-8'))
k = k.replace('\xa0','')
k = k.replace('\u0192','')
# 正则表达式子抓取访问量
b = re.search(r'<dt>访问:</dt>\n(\s*)<dd title="(\d*)',k).group(0)
b = re.search(r'\d+',b).group(0)
b = '访问:'+b
print(b)
f.write(k)
f.close()
# 记录每日访问次数
f = open('website_visit_time.txt', 'a+')
localtime = time.asctime( time.localtime(time.time()))
f.write(localtime)
f.write('\n')
f.write(b)
f.write('\n')
f.close()
print('Program Done')
结果:
website_visit_time.txt: