()
| 3 | from urllib.parse import urljoin |
| 4 | |
| 5 | def get_github_data(): |
| 6 | url = "https://github.com/trending" |
| 7 | headers = { |
| 8 | "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", |
| 9 | "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", |
| 10 | "cache-control": "no-cache", |
| 11 | "pragma": "no-cache", |
| 12 | "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"", |
| 13 | "sec-ch-ua-mobile": "?0", |
| 14 | "sec-ch-ua-platform": "\"Windows\"", |
| 15 | "sec-fetch-dest": "document", |
| 16 | "sec-fetch-mode": "navigate", |
| 17 | "sec-fetch-site": "same-origin", |
| 18 | "sec-fetch-user": "?1", |
| 19 | "upgrade-insecure-requests": "1", |
| 20 | } |
| 21 | response = requests.get(url, headers=headers, timeout=30) |
| 22 | doc = pyquery.PyQuery(response.text) |
| 23 | data = [] |
| 24 | |
| 25 | items = doc("div>article").items() |
| 26 | for item in items: |
| 27 | title = item.find("h2 a").text().split("/")[-1].strip() |
| 28 | link = urljoin(url, item.find("h2 a").attr("href")) |
| 29 | hotScore = item.find("h2~div>a").text().split(" ")[0].replace(',', '') |
| 30 | data.append({ |
| 31 | "title": title, |
| 32 | "url": link, |
| 33 | "hotScore": hotScore |
| 34 | }) |
| 35 | return {"data":data} |
nothing calls this directly
no outgoing calls
no test coverage detected