Skip to content

Commit f526284

Browse files
Merge pull request #2380 from Kalivarapubindusree/github
GitHub_Traffic Script is added
2 parents 0206ad7 + 9295ab9 commit f526284

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Github_Traffic/Github_Traffic.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
4+
def get_github_traffic(repo_url):
5+
response = requests.get(repo_url)
6+
soup = BeautifulSoup(response.content, 'html.parser')
7+
8+
# Find the element containing the traffic data
9+
traffic_element = soup.find('a', {'data-tab-item': 'i4traffic-tab'})
10+
11+
if traffic_element:
12+
# Extract the traffic data
13+
traffic_data = traffic_element.find('span', {'class': 'Counter'}).text.strip()
14+
return traffic_data
15+
else:
16+
return "Traffic data not found."
17+
18+
if _name_ == "_main_":
19+
repo_url = 'https://github.com/username/repository'
20+
traffic_data = get_github_traffic(repo_url)
21+
print(f"Traffic data: {traffic_data}")

Github_Traffic/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GitHub does not have an official API endpoint to retrieve traffic data directly. However, you can use the requests library in Python to send HTTP requests to the GitHub website and parse the HTML content to extract traffic data from the repository page.
2+
3+
Please note that web scraping without proper authorization might violate GitHub's terms of service. Ensure you comply with their policies and consider using GitHub's official API if available for your use case.

0 commit comments

Comments
 (0)