鍗氬璁块棶浜烘暟缁熻
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鍗氬璁块棶浜烘暟缁熻相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%8d%9a%e5%ae%a2' title='鍗氬'>鍗氬
change blank target date int pycharm 鏁板瓧 page寰堟棭涔嬪墠灏卞啓浜嗚繖涓唬鐮侊紝浠婂ぉ閲嶆柊鏇存柊涓€涓?/p>
鍙戠幇瀵瑰崈鍒嗕綅鏁板瓧鐨勫尮閰嶆湁浜沚ug
鍙﹀瀵规潵鑷笉鍚屽湴鍖虹殑鏁版嵁娌¤繘琛岀埇鍙栥€?/p>
鐖彇鏁版嵁锛?a href="http://s04.flagcounter.com/more7/XTPq/" target="_blank">http://s04.flagcounter.com/more7/XTPq/
澶勭悊閫昏緫锛?/p>
1. 鐖彇鏁版嵁
2. 鏋勯€犳暟缁勶細鏃ユ湡锛屽崥瀹㈣闂噺锛宖lag璁块棶閲?/p>
3. 淇濆瓨鏁版嵁鍒版枃浠?/p>
4. 淇濆瓨pickle鏂囦欢
5. 鐢熸垚璁块棶鎶樼嚎鍥?/p>
鐖彇浠g爜濡備笅鎵€绀猴紝璇︾粏浠g爜瑙佸紑婧愯闂細https://github.com/zpfbuaa/blogVisitors
# -*- coding: utf-8 -*- # @Time : 2018/5/25 涓嬪崍1:15 # @Author : 浼婄敻涓€鐐?/span> # @FileName: gethtml.py # @Software: PyCharm # @Blog : http://zpfbuaa.github.io import requests import re import time import os date_pt = re.compile(鈥?/span><font face=arial size=-1>(w+ d+, d+)鈥?/span>) visitors_pt = re.compile(鈥?/span><font face=arial size=2>(w+)</td><td>鈥?/span>) flagViews_pt = re.compile(鈥?/span><font face=arial size=2>(S+)</font></td></tr>鈥?/span>) def getTotalBlog(url, pages): date = [] visitors = [] flagViews = [] for page in range(1, pages+1): newUrl = url + str(page) print(newUrl) html = requests.get(newUrl).text item_date = date_pt.findall(html) item_visitors = visitors_pt.findall(html) item_flagViews = flagViews_pt.findall(html) date.extend(item_date) visitors.extend(item_visitors) flagViews.extend(item_flagViews) return date, visitors, flagViews def change_data(date, visitors, flagViews): print(len(visitors)) print(len(flagViews)) for i in range(0, len(date)): str_visitor = str(visitors[i]) str_flagViews = str(flagViews[i]) if (str_visitor.find(鈥?/span>,鈥?/span>) != -1): v_split = str_visitor.split(鈥?/span>,鈥?/span>) visitors[i] = int(v_split[0]) * 1000 + int(v_split[1]) else: visitors[i] = int(str_visitor) if (str_flagViews.find(鈥?/span>,鈥?/span>) != -1): f_split = str_flagViews.split(鈥?/span>,鈥?/span>) flagViews[i] = int(f_split[0]) * 1000 + int(f_split[1]) else: flagViews[i] = int(str_flagViews) return date, visitors, flagViews def printData(date, visitors, flagViews): print(鈥?/span>Date Visitors Flag Counter Views鈥?/span>) for i in range(0, len(date)): print(date[i],visitors[i],flagViews[i]) def writeToFile(date, visitors, flagViews, data_root=鈥?/span>data/鈥?/span>): today = time.strftime(鈥?/span>%Y%m%d鈥?/span>, time.localtime(time.time())) data_file = data_root+鈥?/span>blog_鈥?/span>+str(today) f = open(data_file,鈥?/span>w+鈥?/span>) header = 鈥?/span>Date Visitors Flag Counter Views鈥?/span>+鈥?/span> 鈥?/span> f.write(header) for i in range(0, len(date)): line = date[i]+鈥?/span> 鈥?/span>+str(visitors[i])+鈥?/span> 鈥?/span>+str(flagViews[i])+鈥?/span> 鈥?/span> f.write(line) f.close() return 1 url = 鈥?/span>http://s04.flagcounter.com/more7/XTPq/鈥?/span> pages = 23 date, visitors, flagViews = getTotalBlog(url, pages) # printData(date, visitors, flagViews) date, visitors, flagViews = change_data(date, visitors, flagViews) # printData(date, visitors, flagViews) flag = writeToFile(date, visitors, flagViews) print(鈥?/span>Data Prepare Done!鈥?/span>)
浠ヤ笅涓烘埅姝㈠埌褰撳墠2019骞?1鏈?2鏃ョ殑璁块棶閲忔姌绾垮浘
璁块棶鍏ュ彛flag缁熻鍥?/p>
涓よ€卍iff宸€?/p>
以上是关于鍗氬璁块棶浜烘暟缁熻的主要内容,如果未能解决你的问题,请参考以下文章