Python內(nèi)容分享活躍站點(diǎn)統(tǒng)計與一些文章鏈接匯總

根據(jù)PythonWeekly每期推薦的文章或教程的引用來源做簡單統(tǒng)計儒搭,推測國外python內(nèi)容分享活躍站點(diǎn)棉浸,并簡單比較優(yōu)質(zhì)python博客或內(nèi)容發(fā)布地的變化揖曾。
舊為2012-2013年左右,新為今年(2017)悯许。格式: [(站點(diǎn)根域名仆嗦, 累計次數(shù)),...]先壕。
(新舊統(tǒng)計期數(shù)不同瘩扼,新:最近20期;舊:最初的81期启上。只統(tǒng)計文章和教程的鏈接邢隧。)


可以看出GithubYoutube一直是活躍的分享站點(diǎn)。wordpress的份額變少了冈在,blogspot基本看不到了倒慧,而medium成為風(fēng)頭正勁。變化還是很大的。

  • PythonWeekly的內(nèi)容相當(dāng)不錯纫谅,可是有時太懶沒看炫贤,錯過不少期,又懶得在郵件列表中一個一個翻付秕,于是做了個爬蟲兰珍,只爬取其中的推薦文章/教程部分,生成一個可以快速瀏覽的markdown列表询吴,便于篩選感興趣的文章掠河,在瀏覽器中打開也很方便搜索。不過猛计,看英文標(biāo)題的掃視速度還是太慢唠摹,申請了個百度翻譯的api機(jī)翻了標(biāo)題,雖然不如谷歌翻譯奉瘤,也勉強(qiáng)能看勾拉,畢竟看中文還是舒服些。點(diǎn)擊下方的鏈接就可以查看匯總文章了盗温。(簡書放不下就放到了github上了藕赞,顯示效果都差不多)

近期文章匯總

初期文章匯總

  • 目前能找到的只有初始81期(對應(yīng)initNews.py)和最近的20期(對應(yīng)recentNews.py)(PythonWeekly 一周一期)。使用代碼需要替換入你自己的百度翻譯api秘鑰卖局。
  • initNews.pyrecentNews.py基本差不多斧蜕。不過,后者只使用了單線程砚偶,比較慢惩激,但是量少,也沒花多少時間蟹演。前者使用了多線程,速度提升很明顯顷蟀,雖然是4倍的量酒请,但差不多一下子就完了。(此外鸣个,百度翻譯api中的query使用'\n'分隔可一次翻譯多個語句)

代碼

  • initNews.py
import requests
from bs4 import BeautifulSoup
import re
# 請?zhí)鎿Q為你的秘鑰
appid = 'yourappid'
secretKey = 'yoursecretkey'

from fake_useragent import UserAgent
ua = UserAgent()
headers = {'user-agent': ua.chrome}

pythonweekly_init_issues_archive_url = (
    'http://www.pythonweekly.com/archive/')

def get_pythonweekly_init_issues_urls():
    url = pythonweekly_init_issues_archive_url
    res = requests.get(url, headers=headers)
    soup = BeautifulSoup(res.content, 'lxml')
    return [[
                a.text.split(' ')[-1].strip(),
                ''.join([url, a['href']]),
            ] for a in soup.select('li a')]

pythonweekly_init_issues_urls = get_pythonweekly_init_issues_urls()

def get_single_issue_info(issue):
    try:
        # issue = [text, url, list] 
        url = issue[1]
        res = requests.get(url, headers=headers)
        soup = BeautifulSoup(res.content, 'lxml')
        content = soup.select_one('td .defaultText')

        try:
            submenus = [i.text for i in content.find_all('strong')]
            for index, menu in enumerate(submenus):
                if re.search('[Aa]rticles', menu):
                    break
            start_text = [menu,]
            end_text = submenus[index+1]
        except:
            # 臟改 
            start_text = ['Articles,\xa0Tutorials and Talks',
                          '\xa0Tutorials and Talks', # 應(yīng)對11,12.html
                          'Articles Tutorials and Talks']
            end_text = 'Interesting Projects, Tools and Libraries'

        flag = 0
        list_ = []
        for s in content.find_all('span'):
            if not flag:
                if s.text not in start_text:
                    continue
                else:
                    flag = 1
                    continue
            if s.text == end_text:
                break
            try:
                one = [s.text.strip(), s.find('a')['href']]
                # print(one)
                list_.append(one)
            except TypeError:
                pass
        # return list_
        issue.append(list_)
        print('下載完成', issue[0])
    except Exception as e:
        print('wrong: ', issue[0], '\n', e)

from multiprocessing.dummy import Pool
pool = Pool(30)
pool.map(get_single_issue_info, pythonweekly_init_issues_urls)
pythonweekly_init_issues = pythonweekly_init_issues_urls


def baidu_translates(query):
    '''
    http://api.fanyi.baidu.com/api/trans/product/apidoc
    '''
    from hashlib import md5
    import random
    
    url = 'http://api.fanyi.baidu.com/api/trans/vip/translate'
    fromLang = 'en'
    toLang = 'zh'
    salt = random.randint(32768, 65536)

    sign = appid + query + str(salt) + secretKey
    m1 = md5()
    m1.update(sign.encode('utf-8'))
    sign = m1.hexdigest()
    
    params = {'appid':appid,
              'q':query,
              'from':fromLang,
              'to':toLang,
              'salt':str(salt),
              'sign':sign,}
    res = requests.get(url, params=params)
    return res.json()['trans_result']

def get_translate(issue):
    articles = issue[-1]
    try:
        result = baidu_translates('\n'.join([i[0] for i in articles]))
        for index, i in enumerate(articles):
            i.append(result[index]['dst'])
        print('翻譯完成', issue[0])
    except:
        print('**翻譯失敗**', issue[0])

pool.map(get_translate, pythonweekly_init_issues)


from jinja2 import Template
table = """
<table>
    {% for issue_num, issue_href, article_lists in issues %}
        {% for article_name, article_href, article_chinese in article_lists %}
        <tr>
            <td><a href='{{issue_href}}'>{{ issue_num }}</a></td>
            <td><a href='{{article_href}}'>{{ article_name }}</a></td>
            <td><a href='{{article_href}}'>{{ article_chinese }}</a></td>
        </tr>
        {% endfor %}
    {% endfor %}
</table>
"""

template = Template(table)
t = template.render(issues=pythonweekly_init_issues)

import time
with open('pythonweekly_init ' + time.ctime().replace(':', '_') + '.html', 'w', encoding='utf-8') as f:
    f.write(t)
    

pool.close()
pool.join()

# https://stackoverflow.com/questions/9626535/get-domain-name-from-url
# get_host = requests.urllib3.util.url.get_host # get_host(i[1])[1]
import tldextract
host_list = [
    tldextract.extract(i[1]).domain
    for *_, articles in pythonweekly_init_issues for i in articles ]

from collections import Counter
counter = Counter(host_list)
print(counter.most_common(20))

with open('pythonweekly_init.md', 'w', encoding='utf-8') as f:
    f.write(u'### PythonWeekly初期文章教程匯總\n')
    f.write(u'|      期號     |     英文名    | 中文名|\n')
    f.write(u'| ------------- |:-------------:| -----:|\n')
    for issue_num, issue_href, article_lists in pythonweekly_init_issues:
        for article_name, article_href, article_chinese in article_lists:
            f.write(('| [{issue_num}]({issue_href}) '
                     '| [{article_name}]({article_href}) '
                     '| [{article_chinese}]({article_href}) '
                     '| \n').format(**locals()))
  • recentNews.py
import requests
from bs4 import BeautifulSoup
import re
# 請?zhí)鎿Q為你的秘鑰
appid = 'yourappid'
secretKey = 'yoursecretkey'


from fake_useragent import UserAgent
ua = UserAgent()
headers = {'user-agent': ua.chrome}

pythonweekly_recent_issues_archive_url = (
    'http://us2.campaign-archive2.com/home/'
    '?u=e2e180baf855ac797ef407fc7&id=9e26887fc5')

def get_pythonweekly_recent_issues_urls():
    
    res = requests.get(pythonweekly_recent_issues_archive_url, headers=headers)
    soup = BeautifulSoup(res.content, 'lxml')
    return [[
                a.text.split(' ')[-1].strip(),
                a['href'],
            ]
            for a in soup.select('li a')]

pythonweekly_recent_issues_urls = get_pythonweekly_recent_issues_urls()

def get_single_issue_info(url):
    res = requests.get(url, headers=headers)
    soup = BeautifulSoup(res.content, 'lxml')
    content = soup.select_one('td .defaultText')

    submenus = [i.text for i in content.find_all('span', attrs={'style':"color:#B22222"})]
    for index, i in enumerate(submenus):
        if re.search('[Aa]rticles', i):
            break
    start_text = i
    end_text = submenus[index+1]

    flag = 0
    list_ = []
    for s in content.find_all('span'):
        if not flag:
            if s.text != start_text:
                continue
            else:
                flag = 1
                continue
        if s.text == end_text:
            break
        try:
            one = [s.text.strip(), s.find('a')['href']]
            # print(one)
            list_.append(one)
        except TypeError:
            pass
    return list_

for i in pythonweekly_recent_issues_urls:
    # [text, url, list] 
    print(i[0])
    i.append(get_single_issue_info(i[1]))

pythonweekly_recent_issues = pythonweekly_recent_issues_urls


def baidu_translate(query):
    '''
    http://api.fanyi.baidu.com/api/trans/product/apidoc
    '''
    from hashlib import md5
    import random

    url = 'http://api.fanyi.baidu.com/api/trans/vip/translate'
    fromLang = 'en'
    toLang = 'zh'
    salt = random.randint(32768, 65536)

    sign = appid + query + str(salt) + secretKey
    m1 = md5()
    m1.update(sign.encode('utf-8'))
    sign = m1.hexdigest()
    
    params = {'appid':appid,
              'q':query,
              'from':fromLang,
              'to':toLang,
              'salt':str(salt),
              'sign':sign,}
    res = requests.get(url, params=params)
    return res.json()['trans_result'][0]['dst']

for *_, articles in pythonweekly_recent_issues:
    for i in articles:
        i.append(baidu_translate(i[0]))
    print('done')


from jinja2 import Template
table = """
<table>
    {% for issue_num, issue_href, article_lists in issues %}
        {% for article_name, article_href, article_chinese in article_lists %}
        <tr>
            <td><a href='{{issue_href}}'>{{ issue_num }}</a></td>
            <td><a href='{{article_href}}'>{{ article_name }}</a></td>
            <td><a href='{{article_href}}'>{{ article_chinese }}</a></td>
        </tr>
        {% endfor %}
    {% endfor %}
</table>
"""

template = Template(table)
t = template.render(issues=pythonweekly_recent_issues)

import time
with open('pythonweekly_recent ' + time.ctime().replace(':', '_') + '.html', 'w', encoding='utf-8') as f:
    f.write(t)

import tldextract
host_list = [
    tldextract.extract(i[1]).domain
    for *_, articles in pythonweekly_recent_issues for i in articles ]

from collections import Counter
counter = Counter(host_list)
counter.most_common(20)


with open('pythonweekly_recent.md', 'w', encoding='utf-8') as f:
    f.write(u'### PythonWeekly文章教程近期匯總\n')
    f.write(u'|      期號     |     英文名    | 中文名|\n')
    f.write(u'| ------------- |:-------------:| -----:|\n')
    for issue_num, issue_href, article_lists in pythonweekly_recent_issues:
        for article_name, article_href, article_chinese in article_lists:
            f.write(('| [{issue_num}]({issue_href}) '
                     '| [{article_name}]({article_href}) '
                     '| [{article_chinese}]({article_href}) '
                     '| \n').format(**locals()))

參考

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末羞反,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子囤萤,更是在濱河造成了極大的恐慌昼窗,老刑警劉巖,帶你破解...
    沈念sama閱讀 223,002評論 6 519
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件涛舍,死亡現(xiàn)場離奇詭異澄惊,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,357評論 3 400
  • 文/潘曉璐 我一進(jìn)店門掸驱,熙熙樓的掌柜王于貴愁眉苦臉地迎上來肛搬,“玉大人,你說我怎么就攤上這事毕贼∥屡猓” “怎么了?”我有些...
    開封第一講書人閱讀 169,787評論 0 365
  • 文/不壞的土叔 我叫張陵鬼癣,是天一觀的道長陶贼。 經(jīng)常有香客問我,道長待秃,這世上最難降的妖魔是什么拜秧? 我笑而不...
    開封第一講書人閱讀 60,237評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮锥余,結(jié)果婚禮上腹纳,老公的妹妹穿的比我還像新娘。我一直安慰自己驱犹,他們只是感情好嘲恍,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,237評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著雄驹,像睡著了一般佃牛。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上医舆,一...
    開封第一講書人閱讀 52,821評論 1 314
  • 那天俘侠,我揣著相機(jī)與錄音,去河邊找鬼蔬将。 笑死爷速,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的霞怀。 我是一名探鬼主播惫东,決...
    沈念sama閱讀 41,236評論 3 424
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼毙石!你這毒婦竟也來了廉沮?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,196評論 0 277
  • 序言:老撾萬榮一對情侶失蹤徐矩,失蹤者是張志新(化名)和其女友劉穎滞时,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體滤灯,經(jīng)...
    沈念sama閱讀 46,716評論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡坪稽,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,794評論 3 343
  • 正文 我和宋清朗相戀三年曼玩,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片刽漂。...
    茶點(diǎn)故事閱讀 40,928評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡演训,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出贝咙,到底是詐尸還是另有隱情样悟,我是刑警寧澤,帶...
    沈念sama閱讀 36,583評論 5 351
  • 正文 年R本政府宣布庭猩,位于F島的核電站窟她,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏蔼水。R本人自食惡果不足惜震糖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,264評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望趴腋。 院中可真熱鬧吊说,春花似錦、人聲如沸优炬。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,755評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蠢护。三九已至雅宾,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間葵硕,已是汗流浹背眉抬。 一陣腳步聲響...
    開封第一講書人閱讀 33,869評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留懈凹,地道東北人蜀变。 一個月前我還...
    沈念sama閱讀 49,378評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像介评,于是被迫代替她去往敵國和親昏苏。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,937評論 2 361

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,341評論 25 707
  • # Python 資源大全中文版 我想很多程序員應(yīng)該記得 GitHub 上有一個 Awesome - XXX 系列...
    aimaile閱讀 26,506評論 6 427
  • 他來了 我站在十一樓已經(jīng)望見 穿著我原來給他買的衣服 背著黃色的蛇皮袋子 一個標(biāo)準(zhǔn)的中國農(nóng)民的樣子 緩緩映入我的眼...
    悠然_3c09閱讀 226評論 5 5
  • 這個曼陀羅畫于我最失落的時候威沫, 女朋友要離我而去回到前男友那里, 而我用盡了一切辦法但無能為力洼专, 焦慮棒掠,憔悴,不甘...
    心理學(xué)者阮健閱讀 583評論 0 1
  • 我之前也有一個樹洞颈墅,是我心里的那個他。五年前大學(xué)畢業(yè)雾袱,我斷斷續(xù)續(xù)也接觸過幾個男生恤筛。曾經(jīng)高傲的堅(jiān)定一個信念,...
    薪薇閱讀 391評論 0 0