鍗氬璁块棶浜烘暟缁熻

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鏃ョ殑璁块棶閲忔姌绾垮浘

鎶€鏈垎浜浘鐗? src=

璁块棶鍏ュ彛flag缁熻鍥?/p>

鎶€鏈垎浜浘鐗? src=

涓よ€卍iff宸€?/p>

鎶€鏈垎浜浘鐗? src=

以上是关于鍗氬璁块棶浜烘暟缁熻的主要内容,如果未能解决你的问题,请参考以下文章

涓篢ypecho澧炲姞鏂囩珷闃呰娆℃暟缁熻鍔熻兘

鐢∟ginx绂佹鍥藉IP璁块棶鎴戠殑缃戠珯...

nginx 鑷缓璇佷功浠ttps 璁块棶

github 璁块棶澶參锛屾€庝箞鍔?锛?/a>

Linux WordPress 璁块棶鍩熷悕涓嬭浇鏂囦欢

Zuul鐨勪娇鐢紝璺敱璁块棶鏄犲皠瑙勫垯