-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (41 loc) · 1.79 KB
/
Copy pathmain.py
File metadata and controls
53 lines (41 loc) · 1.79 KB
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
48
49
50
51
52
53
import random
import requests
import json
class GitHubCrawler:
def __init__(self, keywords, proxies, search_type):
self.keywords = keywords
self.proxies = proxies
self.search_type = search_type
def get_random_proxy(self):
return random.choice(self.proxies)
def search_github(self):
results = []
for keyword in self.keywords:
url = f'https://github.com/search?q={keyword}&type={self.search_type}'
proxy = self.get_random_proxy()
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
try:
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
json_data = response.json()
search_results = json_data['payload']['results']
for result in search_results:
if result['repo'] is not None:
results.append({
'url': f'https://github.com/{result["repo"]["repository"]["owner_login"]}/{result["repo"]["repository"]["name"]}',
'extra': {
'owner': result["repo"]["repository"]["owner_login"],
'language_stats': result["language"]
}
})
except requests.RequestException as e:
print(f"Error: {e}")
return results
if __name__ == '__main__':
crawler = GitHubCrawler(
keywords=['css'],
proxies=['167.71.41.76:8080', '167.71.41.76:8080'],
search_type='Repositories'
)
results = crawler.search_github()
print(json.dumps(results, indent=2))