-
Notifications
You must be signed in to change notification settings - Fork 32
/
github_followXXXList.py
47 lines (41 loc) · 1.47 KB
/
github_followXXXList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding:utf-8
import requests
from bs4 import BeautifulSoup
import time
url = 'https://github.com/'
default_url = 'https://github.com'
headers = {
'User-Agent': '' # ur user-Agent here
}
result_lists = []
def count(Tag):
str = Tag.get_text().replace(' ','').strip('\n').encode('utf-8')
leng = len(str)-1
if str[-1] == 'k':
count = int(float(str[:leng]) * 1000)
else:
count = int(str)
return count
def get_follow_counts_pages(url,person,boo):
followXXX = 'following' if boo else 'followers'
true_url = url + person + '?tab=' + followXXX
data = requests.get(true_url, headers=headers)
soup = BeautifulSoup(data.text, 'lxml')
counts = soup.select('div.user-profile-nav > nav > a.underline-nav-item > span')
# 如果boo 是真,说明是following ,counts[3]
if boo:
return (count(counts[3]))/51 + 1
else:
return (count(counts[2]))/51 + 1
def get_follow_lists(url,person,boo,pages = 1):
# 组url
followXXX = 'following' if boo else 'followers'
true_url = url + person + '?page=' + str(pages) + '&tab=' + followXXX
data = requests.get(true_url, headers=headers)
soup = BeautifulSoup(data.text, 'lxml')
lists = soup.select('div.d-table > div.d-table-cell > a.d-inline-block')
for i in lists:
result_lists.append(default_url+i.get('href'))
print default_url+i.get('href')
print len(result_lists)
return result_lists