欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Python中如何使用Github用戶數(shù)據(jù)爬蟲

Python中如何使用Github用戶數(shù)據(jù)爬蟲,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

成都創(chuàng)新互聯(lián)成立于2013年,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務公司,擁有項目網(wǎng)站制作、做網(wǎng)站網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元孝義做網(wǎng)站,已為上家服務,為孝義各地企業(yè)和個人服務,聯(lián)系電話:028-86922220

前言

主要目標是爬取Github上指定用戶的粉絲數(shù)據(jù)以及對爬取到的數(shù)據(jù)進行一波簡單的可視化分析。 讓我們愉快地開始吧~

開發(fā)工具

Python版本:3.6.4

相關模塊:

bs4模塊;

requests模塊;

argparse模塊;

pyecharts模塊;

以及一些python自帶的模塊。

環(huán)境搭建

安裝Python并添加到環(huán)境變量,pip安裝需要的相關模塊即可。

數(shù)據(jù)爬取

感覺好久沒用beautifulsoup了,所以今天就用它來解析網(wǎng)頁從而獲得我們自己想要的數(shù)據(jù)唄。以我自己的賬戶為例:

Python中如何使用Github用戶數(shù)據(jù)爬蟲

我們先抓取所有關注者的用戶名,它在類似如下圖所示的標簽中:

Python中如何使用Github用戶數(shù)據(jù)爬蟲

用beautifulsoup可以很方便地提取它們:

'''獲得followers的用戶名'''
def getfollowernames(self):
    print('[INFO]: 正在獲取%s的所有followers用戶名...' % self.target_username)
    page = 0
    follower_names = []
    headers = self.headers.copy()
    while True:
        page += 1
        followers_url = f'https://github.com/{self.target_username}?page={page}&tab=followers'
        try:
            response = requests.get(followers_url, headers=headers, timeout=15)
            html = response.text
            if 've reached the end' in html:
                break
            soup = BeautifulSoup(html, 'lxml')
            for name in soup.find_all('span', class_='link-gray pl-1'):
                print(name)
                follower_names.append(name.text)
            for name in soup.find_all('span', class_='link-gray'):
                print(name)
                if name.text not in follower_names:
                    follower_names.append(name.text)
        except:
            pass
        time.sleep(random.random() + random.randrange(0, 2))
        headers.update({'Referer': followers_url})
    print('[INFO]: 成功獲取%s的%s個followers用戶名...' % (self.target_username, len(follower_names)))
    return follower_names

接著,我們就可以根據(jù)這些用戶名進入到他們的主頁來抓取對應用戶的詳細數(shù)據(jù)了,每個主頁鏈接的構(gòu)造方式為:

https://github.com/ + 用戶名
例如: https://github.com/CharlesPikachu

我們想要抓取的數(shù)據(jù)包括:

Python中如何使用Github用戶數(shù)據(jù)爬蟲

同樣地,我們利用beautifulsoup來提取這些信息:

for idx, name in enumerate(follower_names):
    print('[INFO]: 正在爬取用戶%s的詳細信息...' % name)
    user_url = f'https://github.com/{name}'
    try:
        response = requests.get(user_url, headers=self.headers, timeout=15)
        html = response.text
        soup = BeautifulSoup(html, 'lxml')
        # --獲取用戶名
        username = soup.find_all('span', class_='p-name vcard-fullname d-block overflow-hidden')
        if username:
            username = [name, username[0].text]
        else:
            username = [name, '']
        # --所在地
        position = soup.find_all('span', class_='p-label')
        if position:
            position = position[0].text
        else:
            position = ''
        # --倉庫數(shù), stars數(shù), followers, following
        overview = soup.find_all('span', class_='Counter')
        num_repos = self.str2int(overview[0].text)
        num_stars = self.str2int(overview[2].text)
        num_followers = self.str2int(overview[3].text)
        num_followings = self.str2int(overview[4].text)
        # --貢獻數(shù)(最近一年)
        num_contributions = soup.find_all('h3', class_='f4 text-normal mb-2')
        num_contributions = self.str2int(num_contributions[0].text.replace('\n', '').replace(' ', ''). \
                            replace('contributioninthelastyear', '').replace('contributionsinthelastyear', ''))
        # --保存數(shù)據(jù)
        info = [username, position, num_repos, num_stars, num_followers, num_followings, num_contributions]
        print(info)
        follower_infos[str(idx)] = info
    except:
        pass
    time.sleep(random.random() + random.randrange(0, 2))

數(shù)據(jù)可視化

這里以我們自己的粉絲數(shù)據(jù)為例,大概1200條吧。

先來看看他們在過去一年里提交的代碼次數(shù)分布吧:

Python中如何使用Github用戶數(shù)據(jù)爬蟲

提交最多的一位名字叫fengjixuchui,在過去一年一共有9437次提交。平均下來,每天都得提交20多次,也太勤快了。Python中如何使用Github用戶數(shù)據(jù)爬蟲

再來看看每個人擁有的倉庫數(shù)量分布唄:

Python中如何使用Github用戶數(shù)據(jù)爬蟲

本以為會是條單調(diào)的曲線,看來低估各位了。

接著來看看star別人的數(shù)量分布唄:

Python中如何使用Github用戶數(shù)據(jù)爬蟲

還行,至少不全都是"潛水白嫖"的Python中如何使用Github用戶數(shù)據(jù)爬蟲

。表揚一下名為lifa123的老哥,竟然給別人了18700個????,也太秀了。Python中如何使用Github用戶數(shù)據(jù)爬蟲

再來看看這1000多個人擁有的粉絲數(shù)量分布唄:

Python中如何使用Github用戶數(shù)據(jù)爬蟲

關于Python中如何使用Github用戶數(shù)據(jù)爬蟲問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關知識。

網(wǎng)站標題:Python中如何使用Github用戶數(shù)據(jù)爬蟲
文章出自:http://aaarwkj.com/article38/gdespp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供Google外貿(mào)網(wǎng)站建設、App設計、品牌網(wǎng)站設計、定制開發(fā)微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化
91麻豆精品国产91久5久久| 亚洲一区二区三区有码| 美女午夜精品国产福利| 美女在线观看av少妇| 久久96国产精品久久秘臀| 国产成人免费视频大全| 欧美久久久久久久黑人| 免费视频观看在线一区二区三区| 日本高清加勒比免费在线| 真做的欧美三级在线观看| 免费av不卡一区二区| 一级片高清在线观看国产| 国产一区二区三区的网站| 国产亚洲欧美精品久久久久久| 男人天堂插插综合搜索| 欧美精品日韩中文字幕在| 日韩精品日本道欧美黄片 | 日韩欧美黄片一区二区三区| 日韩成人大片在线播放| 久久免费欧美日韩亚洲| 中文字幕人妻熟女在线| 亚洲精品欧美综合第四区| 久久免费看少妇高潮免费| 麻豆剧传媒国产精选av| 久久精品亚洲夜色国产av| 欧美老熟妇子乱视频在线| 日本高清av一区二区| 天天操天天日天天干夜夜情欢| 素人人妻一区二区三区| 国产一级夫妻性生活欧美| 精品亚洲一区二区三区| 国产三级在线播放完整| 日本韩国精品视频在线| 久久最新视频中文字幕| 精品国产50部农村老熟女av| 中文字幕在线一区国产精品| 国内精品一区二区欧美| 日韩亚洲欧美另类精品| 国产乱码免费一区二区三区| 992免费影院 在线观看| 亚洲成人高清在线播放|