From fbe830bd04db7222746a63985df436544b29ee06 Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 6 Nov 2024 17:27:29 +0800 Subject: [PATCH 01/28] feat: zhihu --- ZhiHu/Billboard.py | 13 +++++++++++++ ZhiHu/Home.py | 34 ++++++++++++++++++++++++++++++++++ ZhiHu/__init__.py | 8 ++++++++ 3 files changed, 55 insertions(+) create mode 100644 ZhiHu/Billboard.py create mode 100644 ZhiHu/Home.py create mode 100644 ZhiHu/__init__.py diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py new file mode 100644 index 0000000..974dcec --- /dev/null +++ b/ZhiHu/Billboard.py @@ -0,0 +1,13 @@ +# 知乎热榜 + +import requests +from bs4 import BeautifulSoup + +def billboard(): + url = 'https://www.zhihu.com/billboard' + res = requests.get(url) + soup = BeautifulSoup(res.text, 'lxml') + titles = soup.find_all('div', class_='HotList-itemTitle') + + for title in titles: + print(title.text) \ No newline at end of file diff --git a/ZhiHu/Home.py b/ZhiHu/Home.py new file mode 100644 index 0000000..24b077e --- /dev/null +++ b/ZhiHu/Home.py @@ -0,0 +1,34 @@ +import requests +from bs4 import BeautifulSoup + +# 登录URL +LOGIN_URL = 'https://www.zhihu.com/login/phone_num' +# 知乎首页 +HOME_URL = 'https://www.zhihu.com/' + +# 用户输入的手机号和密码 +phone_num = input('手机号码:') +password = input('密码:') + +def get_data(url): + headers = { + 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36', + 'refer': 'https://www.zhihu.com' + } + + try: + res = requests.get(url, headers=headers) + res.encoding = res.apparent_encoding + res.raise_for_status() + return res + except requests.HTTPError as e: + print("HTTPError", e) + except requests.RequestException as e: + print(e) + +def home(): + url = 'https://www.zhihu.com/' + data = get_data(url) + html = BeautifulSoup(data.text, 'lxml') + print(html) diff --git a/ZhiHu/__init__.py b/ZhiHu/__init__.py new file mode 100644 index 0000000..a593c61 --- /dev/null +++ b/ZhiHu/__init__.py @@ -0,0 +1,8 @@ +from Billboard import billboard +from Home import home + +def main(): + home() + +if __name__ == '__main__': + main() \ No newline at end of file From db9445fd4292451209cc072b56de6aa898955d91 Mon Sep 17 00:00:00 2001 From: skillnull Date: Thu, 7 Nov 2024 15:14:54 +0800 Subject: [PATCH 02/28] feat: update --- ZhiHu/Home.py | 34 ---------------------------------- ZhiHu/__init__.py | 3 +-- 2 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 ZhiHu/Home.py diff --git a/ZhiHu/Home.py b/ZhiHu/Home.py deleted file mode 100644 index 24b077e..0000000 --- a/ZhiHu/Home.py +++ /dev/null @@ -1,34 +0,0 @@ -import requests -from bs4 import BeautifulSoup - -# 登录URL -LOGIN_URL = 'https://www.zhihu.com/login/phone_num' -# 知乎首页 -HOME_URL = 'https://www.zhihu.com/' - -# 用户输入的手机号和密码 -phone_num = input('手机号码:') -password = input('密码:') - -def get_data(url): - headers = { - 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36', - 'refer': 'https://www.zhihu.com' - } - - try: - res = requests.get(url, headers=headers) - res.encoding = res.apparent_encoding - res.raise_for_status() - return res - except requests.HTTPError as e: - print("HTTPError", e) - except requests.RequestException as e: - print(e) - -def home(): - url = 'https://www.zhihu.com/' - data = get_data(url) - html = BeautifulSoup(data.text, 'lxml') - print(html) diff --git a/ZhiHu/__init__.py b/ZhiHu/__init__.py index a593c61..bbfa552 100644 --- a/ZhiHu/__init__.py +++ b/ZhiHu/__init__.py @@ -1,8 +1,7 @@ from Billboard import billboard -from Home import home def main(): - home() + billboard() if __name__ == '__main__': main() \ No newline at end of file From e08e0d97ee16bc7f7d8bfcf742bc9ef3927ddfb8 Mon Sep 17 00:00:00 2001 From: skillnull Date: Fri, 8 Nov 2024 11:14:42 +0800 Subject: [PATCH 03/28] feat: update --- ZhiHu/Billboard.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py index 974dcec..a6c3a5d 100644 --- a/ZhiHu/Billboard.py +++ b/ZhiHu/Billboard.py @@ -2,12 +2,16 @@ import requests from bs4 import BeautifulSoup +import json def billboard(): url = 'https://www.zhihu.com/billboard' res = requests.get(url) soup = BeautifulSoup(res.text, 'lxml') - titles = soup.find_all('div', class_='HotList-itemTitle') + data = soup.find('script',id='js-initialData').get_text() + hotList = json.loads(data)['initialState']['topstory']['hotList'] + # print(json.dumps(hotList, indent=2, ensure_ascii=False)) - for title in titles: - print(title.text) \ No newline at end of file + for item in hotList: + print(item['target']['titleArea']['text']) + print('\r\n\t--------', item['target']['excerptArea']['text'], '\r\n') \ No newline at end of file From 1640b12c22530e86921a6d67b10d5d4965ca8144 Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 13 Nov 2024 10:58:52 +0800 Subject: [PATCH 04/28] feat: update readme --- README.md | 6 ++++++ ZhiHu/Billboard.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3580cb5..a25e92c 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,9 @@ +*
+ 知乎 + + - [知乎热榜](/ZhiHu/Billboard.py) + +
diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py index a6c3a5d..828728a 100644 --- a/ZhiHu/Billboard.py +++ b/ZhiHu/Billboard.py @@ -14,4 +14,4 @@ def billboard(): for item in hotList: print(item['target']['titleArea']['text']) - print('\r\n\t--------', item['target']['excerptArea']['text'], '\r\n') \ No newline at end of file + print('\r\n\t--------', item['target']['excerptArea']['text'], '\r\n') From 42e0a0a57eeff9c4b18905666cd65ca850226fd7 Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 13 Nov 2024 14:58:53 +0800 Subject: [PATCH 05/28] feat: update readme --- FileHandler/Excel.py | 5 +++++ Get-Books/main.py | 2 +- README.md | 2 +- ZhiHu/Billboard.py | 5 ++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/FileHandler/Excel.py b/FileHandler/Excel.py index 0c5f456..ad8dfaf 100644 --- a/FileHandler/Excel.py +++ b/FileHandler/Excel.py @@ -1,3 +1,8 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function 处理 Excel + import time from tqdm import tqdm import requests diff --git a/Get-Books/main.py b/Get-Books/main.py index 3aa5f6f..303869f 100644 --- a/Get-Books/main.py +++ b/Get-Books/main.py @@ -40,4 +40,4 @@ def saveToTxt(comments, title): if __name__ == '__main__': - getContent() + getContent() \ No newline at end of file diff --git a/README.md b/README.md index a25e92c..8f90f50 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ *
文件处理 - - [Excel](/FileHandler/__init__.py) + - [Excel](/FileHandler/Excel.py)
diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py index 828728a..4a7e22e 100644 --- a/ZhiHu/Billboard.py +++ b/ZhiHu/Billboard.py @@ -1,4 +1,7 @@ -# 知乎热榜 +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function 知乎热榜 import requests from bs4 import BeautifulSoup From e20fbae40e91da10d04fde961ce5ba7a964d7fad Mon Sep 17 00:00:00 2001 From: skillnull Date: Thu, 14 Nov 2024 16:53:41 +0800 Subject: [PATCH 06/28] feat: hotlist --- Headless/BaiduHot.py | 15 ++++++++++++++ Headless/__init__.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 Headless/BaiduHot.py create mode 100644 Headless/__init__.py diff --git a/Headless/BaiduHot.py b/Headless/BaiduHot.py new file mode 100644 index 0000000..aa27b37 --- /dev/null +++ b/Headless/BaiduHot.py @@ -0,0 +1,15 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function 百度热搜 + +from bs4 import BeautifulSoup +import json + +def BaiduHot(page_source): + soup = BeautifulSoup(page_source, 'lxml') + data = soup.find('textarea', id='hotsearch_data').get_text() + hotList = json.loads(data)['hotsearch'] + + for item in hotList: + print(f"{int(item['index'])+1}. {item['card_title']}") diff --git a/Headless/__init__.py b/Headless/__init__.py new file mode 100644 index 0000000..a1cadfa --- /dev/null +++ b/Headless/__init__.py @@ -0,0 +1,47 @@ +import time +from selenium.webdriver import Chrome +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.common.by import By +from BaiduHot import BaiduHot + +fun_type = '' + +def main(skip_tips): + opt = Options() + opt.add_argument('--headless') + opt.add_argument('--disable-gpu') + # 本地 chromedriver + service = Service('/Users/macadmin/Public/chromedriver') + web = Chrome(service=service, options=opt) + web.get('https://www.baidu.com') + + global fun_type + + if not skip_tips: + print('==================') + print('=== 1.百度热搜 ===') + print('=== 2.百度搜索 ===') + print('==================') + fun_type = input('请输入对应编号选择功能:') + + if fun_type == '1': + BaiduHot(web.page_source) + elif fun_type == '2': + search_input = web.find_element(By.ID, 'kw') + search_btn = web.find_element(By.ID, 'su') + search_input.clear() + search_input_value = input('\r\n请输入搜索内容:') + search_input.send_keys(search_input_value) + search_btn.send_keys(Keys.ENTER) + time.sleep(1) + print(web.title) + else: + fun_type = '1' + main(True) + + web.close() + +if __name__ == '__main__': + main(False) \ No newline at end of file From 7fc152d3b0059e71cd4d13ebeb29110bba36c88d Mon Sep 17 00:00:00 2001 From: skillnull Date: Fri, 15 Nov 2024 16:42:00 +0800 Subject: [PATCH 07/28] feat: baidu search --- Headless/BaiduHot.py | 4 ++-- Headless/BaiduSearch.py | 16 ++++++++++++++++ Headless/__init__.py | 3 ++- ZhiHu/Billboard.py | 4 ++-- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 Headless/BaiduSearch.py diff --git a/Headless/BaiduHot.py b/Headless/BaiduHot.py index aa27b37..4271759 100644 --- a/Headless/BaiduHot.py +++ b/Headless/BaiduHot.py @@ -7,8 +7,8 @@ import json def BaiduHot(page_source): - soup = BeautifulSoup(page_source, 'lxml') - data = soup.find('textarea', id='hotsearch_data').get_text() + html = BeautifulSoup(page_source, 'lxml') + data = html.find('textarea', id='hotsearch_data').get_text() hotList = json.loads(data)['hotsearch'] for item in hotList: diff --git a/Headless/BaiduSearch.py b/Headless/BaiduSearch.py new file mode 100644 index 0000000..8c30306 --- /dev/null +++ b/Headless/BaiduSearch.py @@ -0,0 +1,16 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function 百度搜索结果 + +from bs4 import BeautifulSoup + +def SearchResult(data): + html = BeautifulSoup(data, 'html.parser') + content = html.find('div', id='content_left') + result = content.find_all('div', class_='result') + + for item in result: + res = item.find_all('h3',class_='c-title') + title = res[0].a.get_text() + print(title) \ No newline at end of file diff --git a/Headless/__init__.py b/Headless/__init__.py index a1cadfa..ed5db34 100644 --- a/Headless/__init__.py +++ b/Headless/__init__.py @@ -5,6 +5,7 @@ from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from BaiduHot import BaiduHot +from BaiduSearch import SearchResult fun_type = '' @@ -36,7 +37,7 @@ def main(skip_tips): search_input.send_keys(search_input_value) search_btn.send_keys(Keys.ENTER) time.sleep(1) - print(web.title) + SearchResult(web.page_source) else: fun_type = '1' main(True) diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py index 4a7e22e..1a528e1 100644 --- a/ZhiHu/Billboard.py +++ b/ZhiHu/Billboard.py @@ -10,8 +10,8 @@ def billboard(): url = 'https://www.zhihu.com/billboard' res = requests.get(url) - soup = BeautifulSoup(res.text, 'lxml') - data = soup.find('script',id='js-initialData').get_text() + html = BeautifulSoup(res.text, 'lxml') + data = html.find('script',id='js-initialData').get_text() hotList = json.loads(data)['initialState']['topstory']['hotList'] # print(json.dumps(hotList, indent=2, ensure_ascii=False)) From bac6d115d68f074b08f9339094091bf5372de57e Mon Sep 17 00:00:00 2001 From: skillnull Date: Fri, 22 Nov 2024 11:11:52 +0800 Subject: [PATCH 08/28] feat: update --- Headless/BaiduSearch.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Headless/BaiduSearch.py b/Headless/BaiduSearch.py index 8c30306..df83a8f 100644 --- a/Headless/BaiduSearch.py +++ b/Headless/BaiduSearch.py @@ -11,6 +11,12 @@ def SearchResult(data): result = content.find_all('div', class_='result') for item in result: - res = item.find_all('h3',class_='c-title') - title = res[0].a.get_text() - print(title) \ No newline at end of file + titles = item.find_all('h3', class_='c-title') + title = titles[0].a.get_text() + print(title) + + answers = item.find_all('span', class_='content-right_1THTn') + if len(answers) > 0: + print('\r\n\t', answers[0].get_text(), '\r\n') + else: + print('\r\n') \ No newline at end of file From 68f94acfbfca1424a977f71c8403d10c87b0f0f7 Mon Sep 17 00:00:00 2001 From: skillnull Date: Tue, 17 Dec 2024 15:01:18 +0800 Subject: [PATCH 09/28] feat: ithome --- ITHome/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ITHome/__init__.py diff --git a/ITHome/__init__.py b/ITHome/__init__.py new file mode 100644 index 0000000..367ef23 --- /dev/null +++ b/ITHome/__init__.py @@ -0,0 +1,26 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function IT之家 + +import requests +from bs4 import BeautifulSoup + +def main(): + url = 'https://www.ithome.com' + res = requests.get(url) + res.encoding = "utf-8" + html = BeautifulSoup(res.text, "lxml") + nnews = html.find('div', id='nnews').find('div', class_="t-b sel clearfix").find_all("li") + + for item in nnews: + text = item.find("a").get_text() + href = item.find("a")["href"] + time = item.find("b") + ad = item.find("b", class_="ad") + if time and ad is None: + print('\r\n', href, '\t', time.get_text()) + print(text) + +if __name__ == '__main__': + main() \ No newline at end of file From eed2af7a3e594310a0ed5be120674b7772f1522e Mon Sep 17 00:00:00 2001 From: skillnull Date: Tue, 17 Dec 2024 15:04:20 +0800 Subject: [PATCH 10/28] feat: update readme --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 8f90f50..2af699d 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,19 @@ - [知乎热榜](/ZhiHu/Billboard.py) + + +*
+ 百度 + + - [百度热搜](/Headless/BaiduHot.py) + - [百度搜索](/Headless/BaiduSearch.py) + +
+ +*
+ IT之家 + + - [IT之家](/ITHome/__init__.py) + +
\ No newline at end of file From d09f8fb583e676f0810c10a525ab277444551ffd Mon Sep 17 00:00:00 2001 From: skillnull Date: Tue, 17 Dec 2024 15:06:06 +0800 Subject: [PATCH 11/28] feat: upadte readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2af699d..0d1dad7 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,6 @@ *
IT之家 - - [IT之家](/ITHome/__init__.py) + - [IT之家剔除广告版](/ITHome/__init__.py)
\ No newline at end of file From f722f7e0950c4d291e0e8b231385815df923a025 Mon Sep 17 00:00:00 2001 From: skillnull Date: Tue, 17 Dec 2024 15:42:38 +0800 Subject: [PATCH 12/28] feat: update --- ITHome/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ITHome/__init__.py b/ITHome/__init__.py index 367ef23..29e58cc 100644 --- a/ITHome/__init__.py +++ b/ITHome/__init__.py @@ -19,8 +19,8 @@ def main(): time = item.find("b") ad = item.find("b", class_="ad") if time and ad is None: - print('\r\n', href, '\t', time.get_text()) - print(text) + print('\r\n%-1s' % href, '\t', time.get_text()) + print('%-1s' % text) if __name__ == '__main__': main() \ No newline at end of file From fbbdb56128bf0807276bb8948721841aeec8fdde Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 18 Dec 2024 17:12:47 +0800 Subject: [PATCH 13/28] =?UTF-8?q?feat:=20=E5=BE=AE=E5=8D=9A=E7=83=AD?= =?UTF-8?q?=E6=90=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WeiBo/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 WeiBo/__init__.py diff --git a/WeiBo/__init__.py b/WeiBo/__init__.py new file mode 100644 index 0000000..4fc8f71 --- /dev/null +++ b/WeiBo/__init__.py @@ -0,0 +1,26 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function 微博热搜 + +import requests +from bs4 import BeautifulSoup + +def main(): + url = 'https://s.weibo.com/top/summary?cate=realtimeho' + headers = { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', + 'Cookie': 'SUB=_2AkMSjdLlf8NxqwFRmfoTzmnhZYl-zwvEieKk0SM-JRMxHRl-yT9kqncGtRB6OQ38CnPn9yiFClr7gzx-ILSdTDQSsBJc; SINAGLOBAL=2793368918109.54.1728635143817; UOR=,,www.google.com; XSRF-TOKEN=ViGiZBdjo8lbaz861ak3d94E; WBPSESS=V0zdZ7jH8_6F0CA8c_ussems2ooi2oISTjoqrgw0BPb0xOXeRG8fgtsfCCwK4z-89gPFGQRBnTVKBZ_pjoEXUS_cWlvZBQM5OWeOo5W3kFwLijeTaAPGZRRSYGC8W2O2yBjahwkNrh-gn4zb9dSzlAmG6gLvY_iRkHtFrrzxdPw=; _s_tentry=-; Apache=9536736833525.607.1734512411018; ULV=1734512411028:3:1:1:9536736833525.607.1734512411018:1731035876374' + } + res = requests.get(url, headers=headers) + res.encoding = "utf-8" + html = BeautifulSoup(res.text, "lxml") + lists_box = html.find('div', id='pl_top_realtimehot') + lists = lists_box.find_all('td', class_='td-02') + + for item in lists: + text = item.find('a').get_text() + print(text, '\r\n') + +if __name__ == '__main__': + main() \ No newline at end of file From ec109c35b8ac4c7b9af5d7134ee5f924a519fbb9 Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 18 Dec 2024 17:15:20 +0800 Subject: [PATCH 14/28] feat: weibo hotlist update --- WeiBo/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WeiBo/__init__.py b/WeiBo/__init__.py index 4fc8f71..015871c 100644 --- a/WeiBo/__init__.py +++ b/WeiBo/__init__.py @@ -20,7 +20,7 @@ def main(): for item in lists: text = item.find('a').get_text() - print(text, '\r\n') + print('\r\n%-10s' % text) if __name__ == '__main__': main() \ No newline at end of file From cb5d9bc3ea06dcb0ad84ad599f3b3a5c20b0ad2c Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 18 Dec 2024 17:22:45 +0800 Subject: [PATCH 15/28] feat: zhihu update --- ZhiHu/Billboard.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py index 1a528e1..a6fefa9 100644 --- a/ZhiHu/Billboard.py +++ b/ZhiHu/Billboard.py @@ -16,5 +16,7 @@ def billboard(): # print(json.dumps(hotList, indent=2, ensure_ascii=False)) for item in hotList: + print(item['target']['imageArea']['url']) + print(item['target']['link']['url']) print(item['target']['titleArea']['text']) print('\r\n\t--------', item['target']['excerptArea']['text'], '\r\n') From 4ba2bd45052dfc62981ab10681356827ca2884cf Mon Sep 17 00:00:00 2001 From: skillnull Date: Thu, 19 Dec 2024 13:02:41 +0800 Subject: [PATCH 16/28] feature: 36kr --- 36kr/__init__.py | 28 ++++++++++++++++++++++++++++ ITHome/__init__.py | 4 ++-- WeiBo/__init__.py | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 36kr/__init__.py diff --git a/36kr/__init__.py b/36kr/__init__.py new file mode 100644 index 0000000..c4f3be2 --- /dev/null +++ b/36kr/__init__.py @@ -0,0 +1,28 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function 36kr + +import requests +from bs4 import BeautifulSoup + +def main(): + url = 'https://36kr.com/newsflashes' + headers = { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', + 'Cookie': 'sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22193d9166304581-06ad155dcc37fc-1e525636-2073600-193d91663051380%22%2C%22%24device_id%22%3A%22193d9166304581-06ad155dcc37fc-1e525636-2073600-193d91663051380%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.google.com%2F%22%2C%22%24latest_referrer_host%22%3A%22www.google.com%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%7D%7D; Hm_lvt_713123c60a0e86982326bae1a51083e1=1734513943; HMACCOUNT=0A571937ECA8AEF4; Hm_lvt_1684191ccae0314c6254306a8333d090=1734513943; Hm_lpvt_713123c60a0e86982326bae1a51083e1=1734514053; Hm_lpvt_1684191ccae0314c6254306a8333d090=1734514053' + } + res = requests.get(url, headers=headers) + res.encoding = "utf-8" + html = BeautifulSoup(res.text, "lxml") + lists_box = html.find('div', class_='newsflash-catalog-flow-list') + lists = lists_box.find_all('div', class_='newsflash-item') + + for item in lists: + text = item.find('a').get_text() + desc = item.find('div', 'item-desc').find('span').get_text() + print('\r\n%s' % text) + print('\t------%s' % desc) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/ITHome/__init__.py b/ITHome/__init__.py index 29e58cc..333c34d 100644 --- a/ITHome/__init__.py +++ b/ITHome/__init__.py @@ -19,8 +19,8 @@ def main(): time = item.find("b") ad = item.find("b", class_="ad") if time and ad is None: - print('\r\n%-1s' % href, '\t', time.get_text()) - print('%-1s' % text) + print('\r\n%s' % href, '\t', time.get_text()) + print('%s' % text) if __name__ == '__main__': main() \ No newline at end of file diff --git a/WeiBo/__init__.py b/WeiBo/__init__.py index 015871c..a5ee766 100644 --- a/WeiBo/__init__.py +++ b/WeiBo/__init__.py @@ -20,7 +20,7 @@ def main(): for item in lists: text = item.find('a').get_text() - print('\r\n%-10s' % text) + print('\r\n%s' % text) if __name__ == '__main__': main() \ No newline at end of file From 66a8013eb035ca6a372a846d61d3e87fe687eb5e Mon Sep 17 00:00:00 2001 From: skillnull Date: Mon, 23 Dec 2024 13:29:43 +0800 Subject: [PATCH 17/28] feat: V2EX --- V2EX/__init__py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 V2EX/__init__py diff --git a/V2EX/__init__py b/V2EX/__init__py new file mode 100644 index 0000000..3df117b --- /dev/null +++ b/V2EX/__init__py @@ -0,0 +1,18 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function V2EX + +import requests +from bs4 import BeautifulSoup + +def all_topics(): + url = 'https://www.v2ex.com/' + res = requests.get(url) + html = BeautifulSoup(res.text, 'lxml') + topics = html.findAll('a', class_='topic-link') + for item in topics: + print('\r\n%s' % item.get_text()) + +if __name__ == '__main__': + all_topics() \ No newline at end of file From ff8f33a060709c798d75e126695632333d471f10 Mon Sep 17 00:00:00 2001 From: skillnull Date: Tue, 21 Jan 2025 17:04:16 +0800 Subject: [PATCH 18/28] feat: history today --- HistoryToday/_360.py | 19 +++++++++++++++++++ HistoryToday/__init__.py | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 HistoryToday/_360.py create mode 100644 HistoryToday/__init__.py diff --git a/HistoryToday/_360.py b/HistoryToday/_360.py new file mode 100644 index 0000000..002accc --- /dev/null +++ b/HistoryToday/_360.py @@ -0,0 +1,19 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function 360历史上的今天 + +import requests +from bs4 import BeautifulSoup + +def getLists(): + url = 'https://hao.360.com/histoday/' + res = requests.get(url) + res.encoding = "utf-8" + html = BeautifulSoup(res.text, "lxml") + items = html.find_all("dl") + + for item in items: + title = item.find("dt").get_text() + desc = item.find("div", class_="desc") + print('\r\n%s' % title, '\n\r\t%s' % desc.get_text().strip()) diff --git a/HistoryToday/__init__.py b/HistoryToday/__init__.py new file mode 100644 index 0000000..7efbf64 --- /dev/null +++ b/HistoryToday/__init__.py @@ -0,0 +1,7 @@ +from _360 import getLists + +def main(): + getLists() + +if __name__ == '__main__': + main() \ No newline at end of file From 7dd0c9cde3e74e8c907402cba73b663b86590c17 Mon Sep 17 00:00:00 2001 From: skillnull Date: Tue, 21 Jan 2025 17:22:19 +0800 Subject: [PATCH 19/28] feat: update readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 0d1dad7..241941b 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,12 @@ - [IT之家剔除广告版](/ITHome/__init__.py) + + + +*
+ 历史上的今天 + + - [历史上的今天](/HistoryToday/__init__.py) +
\ No newline at end of file From 6d28fa5392efc1fb0d6860ff202a8bc0102594fb Mon Sep 17 00:00:00 2001 From: skillnull Date: Tue, 21 Jan 2025 17:24:14 +0800 Subject: [PATCH 20/28] feat: update readme --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 241941b..21c5a14 100644 --- a/README.md +++ b/README.md @@ -54,4 +54,26 @@ - [历史上的今天](/HistoryToday/__init__.py) + + +*
+ 36kr + + - [36kr](/36kr/__init__.py) + +
+ +*
+ V2EX + + - [V2EX](/V2EX/__init__.py) + +
+ + +*
+ 微博热搜 + + - [微博热搜](/WeiBo/__init__.py) +
\ No newline at end of file From 2b81e33b9900599e62bb01ff3ee182b271dfbba6 Mon Sep 17 00:00:00 2001 From: skillnull Date: Mon, 10 Mar 2025 15:40:42 +0800 Subject: [PATCH 21/28] feat: NHK --- NHK/__init__.py | 28 ++++++++++++++++++++++++++++ README.md | 7 +++++++ 2 files changed, 35 insertions(+) create mode 100644 NHK/__init__.py diff --git a/NHK/__init__.py b/NHK/__init__.py new file mode 100644 index 0000000..7e72cdd --- /dev/null +++ b/NHK/__init__.py @@ -0,0 +1,28 @@ +#!/usr/local/bin/python3.9 +# -*- coding: utf-8 -*- +# @Author skillnull +# @Function NHK + +import requests +from bs4 import BeautifulSoup +from googletrans import Translator +import asyncio + +async def japan(): + url = 'https://www3.nhk.or.jp/news/' + headers = { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1', + 'Referer': 'https://www3.nhk.or.jp/news/' + } + res = requests.get(url, headers=headers) + res.encoding = 'utf-8' + html = BeautifulSoup(res.text, 'lxml') + title = html.find_all('em', class_='title') + + for item in title: + traslator = Translator() + res = await traslator.translate(item.get_text(), src='auto', dest='zh-CN') + print('\r\n%s' % res.text) + +if __name__ == '__main__': + asyncio.run(japan()) \ No newline at end of file diff --git a/README.md b/README.md index 21c5a14..75403fe 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,11 @@ - [微博热搜](/WeiBo/__init__.py) + + +*
+ 日本NHK + + - [日本NHK](/NHK/__init__.py) +
\ No newline at end of file From 7f9dc79c869487c6291dd258c3c2ad546e28981d Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 30 Apr 2025 11:25:51 +0800 Subject: [PATCH 22/28] feat: update zhihu --- ZhiHu/Billboard.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py index a6fefa9..584c264 100644 --- a/ZhiHu/Billboard.py +++ b/ZhiHu/Billboard.py @@ -9,7 +9,11 @@ def billboard(): url = 'https://www.zhihu.com/billboard' - res = requests.get(url) + headers = { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1', + 'Cookie': '_xsrf=sHUJiCNw433TP8JWeGwBuH8m6P9e23rg; _zap=a4d60fe1-724a-4ff1-a7e1-7671bc9966c8; d_c0=AAAScU_xARqPTqLlzjwIYBJGOGsANhNePNY=|1739586965; HMACCOUNT=E34CE8E06DC2A079; q_c1=fa0db57489034c4caa440cae3f486618|1743410282000|1743410282000; z_c0=2|1:0|10:1745301492|4:z_c0|80:MS4xR0ZkbUFnQUFBQUFtQUFBQVlBSlZUZlI5OUdoX29FRlZLWU80MUhRV3JQWnlfRzV6ZnV0SnpBPT0=|20f2f3458f09c7830d0fae1fb7ffe6ad40a5fc2e180706db7fe812140d585692; tst=r; __zse_ck=004_NKqoEtUKkl=uDbeZ1yhBFZJwN=lpK35ot8N2HyJ=RsLSuk4Qt=J031OKD62FyImAZr0qTFwW/7hr/aLUDlncEBY989uo4OQSrXqSgQCfZALoGZnNRI0tj4uuFHGUUXpb-AQbn1M3XUZ4tJYlqJnI+oeGufA/Df6lJQ37TbbdKVdBwHgombXTBrU8prG0uoAEdIIBeNt0skeVrKP75zdUK+kT0YWkGAlFqGV1Im2FcnC87378hItOGDyarKZ58ihCt; SESSIONID=xEotaBEEMcHqcCh3MOS0XuMPsodWY6VDfAFDQmFnnPr; JOID=UVEcAE3Y12NN1Wh-CNjou3uKmXAYqpIGPLEgO0eQvis2sy4cO1JKfSXaYnQHfEfSnBimk7fYZ-Bs_wPCRgI74Zg=; osd=UVkSBErY321J0mh2Btzvu3OEnXcYopwCO7EoNUOXviM4tykcM1xOeiXSbHAAfE_cmB-mm7ncYOBk8QfFRgo15Z8=; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1745983374; Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49=1745983374; BEC=4da336ae0b6517487a94031e0c3cbd90' + } + res = requests.get(url, headers=headers) html = BeautifulSoup(res.text, 'lxml') data = html.find('script',id='js-initialData').get_text() hotList = json.loads(data)['initialState']['topstory']['hotList'] From 122a93b2675bc9b894f3dce31b1cdf3f66e43c07 Mon Sep 17 00:00:00 2001 From: skillnull Date: Mon, 21 Jul 2025 19:05:33 +0800 Subject: [PATCH 23/28] feat: zhihu cookie update --- ZhiHu/Billboard.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py index 584c264..2f3eab7 100644 --- a/ZhiHu/Billboard.py +++ b/ZhiHu/Billboard.py @@ -10,8 +10,8 @@ def billboard(): url = 'https://www.zhihu.com/billboard' headers = { - 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1', - 'Cookie': '_xsrf=sHUJiCNw433TP8JWeGwBuH8m6P9e23rg; _zap=a4d60fe1-724a-4ff1-a7e1-7671bc9966c8; d_c0=AAAScU_xARqPTqLlzjwIYBJGOGsANhNePNY=|1739586965; HMACCOUNT=E34CE8E06DC2A079; q_c1=fa0db57489034c4caa440cae3f486618|1743410282000|1743410282000; z_c0=2|1:0|10:1745301492|4:z_c0|80:MS4xR0ZkbUFnQUFBQUFtQUFBQVlBSlZUZlI5OUdoX29FRlZLWU80MUhRV3JQWnlfRzV6ZnV0SnpBPT0=|20f2f3458f09c7830d0fae1fb7ffe6ad40a5fc2e180706db7fe812140d585692; tst=r; __zse_ck=004_NKqoEtUKkl=uDbeZ1yhBFZJwN=lpK35ot8N2HyJ=RsLSuk4Qt=J031OKD62FyImAZr0qTFwW/7hr/aLUDlncEBY989uo4OQSrXqSgQCfZALoGZnNRI0tj4uuFHGUUXpb-AQbn1M3XUZ4tJYlqJnI+oeGufA/Df6lJQ37TbbdKVdBwHgombXTBrU8prG0uoAEdIIBeNt0skeVrKP75zdUK+kT0YWkGAlFqGV1Im2FcnC87378hItOGDyarKZ58ihCt; SESSIONID=xEotaBEEMcHqcCh3MOS0XuMPsodWY6VDfAFDQmFnnPr; JOID=UVEcAE3Y12NN1Wh-CNjou3uKmXAYqpIGPLEgO0eQvis2sy4cO1JKfSXaYnQHfEfSnBimk7fYZ-Bs_wPCRgI74Zg=; osd=UVkSBErY321J0mh2Btzvu3OEnXcYopwCO7EoNUOXviM4tykcM1xOeiXSbHAAfE_cmB-mm7ncYOBk8QfFRgo15Z8=; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1745983374; Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49=1745983374; BEC=4da336ae0b6517487a94031e0c3cbd90' + 'User-Agent': 'Mozilla/5.0 (Linux; Android 7.0; SM-G950U Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Mobile Safari/537.36', + 'Cookie': '_xsrf=sHUJiCNw433TP8JWeGwBuH8m6P9e23rg; _zap=a4d60fe1-724a-4ff1-a7e1-7671bc9966c8; d_c0=AAAScU_xARqPTqLlzjwIYBJGOGsANhNePNY=|1739586965; q_c1=fa0db57489034c4caa440cae3f486618|1743410282000|1743410282000; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1750662082,1752473685; HMACCOUNT=E34CE8E06DC2A079; __zse_ck=004_z3IDUPO9OuejO4stBVRKkNPYTGhTiMl/XKD6XtNIu3g2Ik1ZEhyxljmlT9Zw6v6OCb4SV8/mQ3GLHIQMcQXodlJUeyw6Gfbi=ubeRLeP6OkqnGRpWk/S5gIdswBaAQH1-eLKiB7dr3GaBtdn6/S7c6sZs80AgMV10uKKeHyL7E4frr9JW7woM/5mfiG7JGGrYjz4+VAuQTfpS4CoSq+mVZiTo+PgW4Sf+o1uUKBI4evUpI1mRNHF3LczfZPn+btrP; Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49=1753095559; SESSIONID=nHaej8y3ffXqJBXNNwrkClKMKncWzOv9LugJxRegbaC; z_c0=2|1:0|10:1753095558|4:z_c0|80:MS4xR0ZkbUFnQUFBQUFtQUFBQVlBSlZUWVpyYTJrTEVPbEhJRFptVk43RkY4ZEtyRGRsMGVPbTNRPT0=|6bebd07d7e8643904d65ad6ede56e5ec7e53d17cce65e4197fcc34fa9cbb13a2; JOID=UFkRC0LMpAJ1KtgHZsac1kB3Iw56oelvEUvje1mhwV8IYZFcLU2wcRci3g5r9xztW4LTjyX-K6QtPBtVTXJhvXY=; osd=VV8dC0rJog51It0BasaU00Z7IwZ_p-VvGU7ld1mpxFkEYZlZK0GweRIk0g5j8hrhW4rWiSn-I6ErMBtdSHRtvX4=; BEC=7e33fec1f95d805b0b89c2974da3470f' } res = requests.get(url, headers=headers) html = BeautifulSoup(res.text, 'lxml') From 947a8d0548d3a6f7254267c392e5f7978d25522b Mon Sep 17 00:00:00 2001 From: skillnull Date: Mon, 15 Sep 2025 15:16:21 +0800 Subject: [PATCH 24/28] feat: update cookie --- ZhiHu/Billboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py index 2f3eab7..77f56d3 100644 --- a/ZhiHu/Billboard.py +++ b/ZhiHu/Billboard.py @@ -11,7 +11,7 @@ def billboard(): url = 'https://www.zhihu.com/billboard' headers = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 7.0; SM-G950U Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Mobile Safari/537.36', - 'Cookie': '_xsrf=sHUJiCNw433TP8JWeGwBuH8m6P9e23rg; _zap=a4d60fe1-724a-4ff1-a7e1-7671bc9966c8; d_c0=AAAScU_xARqPTqLlzjwIYBJGOGsANhNePNY=|1739586965; q_c1=fa0db57489034c4caa440cae3f486618|1743410282000|1743410282000; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1750662082,1752473685; HMACCOUNT=E34CE8E06DC2A079; __zse_ck=004_z3IDUPO9OuejO4stBVRKkNPYTGhTiMl/XKD6XtNIu3g2Ik1ZEhyxljmlT9Zw6v6OCb4SV8/mQ3GLHIQMcQXodlJUeyw6Gfbi=ubeRLeP6OkqnGRpWk/S5gIdswBaAQH1-eLKiB7dr3GaBtdn6/S7c6sZs80AgMV10uKKeHyL7E4frr9JW7woM/5mfiG7JGGrYjz4+VAuQTfpS4CoSq+mVZiTo+PgW4Sf+o1uUKBI4evUpI1mRNHF3LczfZPn+btrP; Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49=1753095559; SESSIONID=nHaej8y3ffXqJBXNNwrkClKMKncWzOv9LugJxRegbaC; z_c0=2|1:0|10:1753095558|4:z_c0|80:MS4xR0ZkbUFnQUFBQUFtQUFBQVlBSlZUWVpyYTJrTEVPbEhJRFptVk43RkY4ZEtyRGRsMGVPbTNRPT0=|6bebd07d7e8643904d65ad6ede56e5ec7e53d17cce65e4197fcc34fa9cbb13a2; JOID=UFkRC0LMpAJ1KtgHZsac1kB3Iw56oelvEUvje1mhwV8IYZFcLU2wcRci3g5r9xztW4LTjyX-K6QtPBtVTXJhvXY=; osd=VV8dC0rJog51It0BasaU00Z7IwZ_p-VvGU7ld1mpxFkEYZlZK0GweRIk0g5j8hrhW4rWiSn-I6ErMBtdSHRtvX4=; BEC=7e33fec1f95d805b0b89c2974da3470f' + 'Cookie': 'srf=sHUJiCNw433TP8JWeGwBuH8m6P9e23rg; _zap=a4d60fe1-724a-4ff1-a7e1-7671bc9966c8; d_c0=AAAScU_xARqPTqLlzjwIYBJGOGsANhNePNY=|1739586965; q_c1=fa0db57489034c4caa440cae3f486618|1743410282000|1743410282000; HMACCOUNT=E34CE8E06DC2A079; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1755503916; __zse_ck=004_OGOj5BgLr/2QHd/3Lv2jaVY2o0ICFpWcDdZEAWuN2VuO9YrWd1E3V4NkSwOVfwN2iyElOlEnK1BwK/ygKMhj=af3kgEvTJ4VVyLlFr2VRgKNrReom2qedlrwt6zXgtHS-7TpBnD7D5PF5rctieuY9gxt70TrSkqWSkM0EnEK+Qd6QNFWB+5bWZrFn+xvgR2bd5NsHkvdDFOLQrDu5AcERAYBaTzKgPYBPibU8O3L6wXuwr/mWLHKSudfJvAo3AB1i; tst=r; SESSIONID=m1UOriomvF6PVGamarxmI7kpR6gCn4SYUHSnbqaYY0p; JOID=W1AXC04Ukfx7zg1SEBWsJUeZ_V4BeKqjObBlN3du1sAhlUYyd7stPBLDBlIX0PAaIZVoicIadptLHaj8uiDpqlk=; osd=WlgXBE4Vmfx0zgxaEBqsJE-Z8l4AcKqsObFtN3hu18ghmkYzf7siPBPLBl0X0fgaLpVpgcIVdppDHaf8uyjppVk=; Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49=1757920432; z_c0=2|1:0|10:1757920434|4:z_c0|80:MS4xR0ZkbUFnQUFBQUFtQUFBQVlBSlZUYzBCckdubkVFdy1QRTBsNFM2a1hFaWdmUFhNMGJJcGF3PT0=|9ae71f9278519581802f7ea7f90404f43f5861606a3b5fafca995ca3d748b667; BEC=eee8906a1fecdebcee3fda89d6b84517' } res = requests.get(url, headers=headers) html = BeautifulSoup(res.text, 'lxml') From 6e7ef2a394044caa40001b5cd7e53ec7dfdf64fe Mon Sep 17 00:00:00 2001 From: skillnull Date: Thu, 11 Dec 2025 14:51:38 +0800 Subject: [PATCH 25/28] feat: update --- .gitignore | 0 36kr/__init__.py | 0 FileHandler/Excel.py | 0 FileHandler/README.md | 0 FileHandler/__init__.py | 0 Get-Books/__init__.py | 0 Get-Books/main.py | 0 Headless/BaiduHot.py | 0 Headless/BaiduSearch.py | 0 Headless/__init__.py | 0 HistoryToday/_360.py | 0 HistoryToday/__init__.py | 0 ITHome/__init__.py | 0 LICENSE | 0 NHK/__init__.py | 0 Netease/README.md | 0 Netease/__init__.py | 0 Netease/musicComments/1454897840/1454897840.html | 0 ...216\253\351\227\256\345\275\222\346\234\237.txt" | 0 Netease/musicComments/wordcloud_bg.jpg | Bin README.md | 0 V2EX/__init__py | 0 WeiBo/__init__.py | 0 ZhiHu/Billboard.py | 0 ZhiHu/__init__.py | 0 25 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 36kr/__init__.py mode change 100644 => 100755 FileHandler/Excel.py mode change 100644 => 100755 FileHandler/README.md mode change 100644 => 100755 FileHandler/__init__.py mode change 100644 => 100755 Get-Books/__init__.py mode change 100644 => 100755 Get-Books/main.py mode change 100644 => 100755 Headless/BaiduHot.py mode change 100644 => 100755 Headless/BaiduSearch.py mode change 100644 => 100755 Headless/__init__.py mode change 100644 => 100755 HistoryToday/_360.py mode change 100644 => 100755 HistoryToday/__init__.py mode change 100644 => 100755 ITHome/__init__.py mode change 100644 => 100755 LICENSE mode change 100644 => 100755 NHK/__init__.py mode change 100644 => 100755 Netease/README.md mode change 100644 => 100755 Netease/__init__.py mode change 100644 => 100755 Netease/musicComments/1454897840/1454897840.html mode change 100644 => 100755 "Netease/musicComments/1454897840/\350\216\253\351\227\256\345\275\222\346\234\237.txt" mode change 100644 => 100755 Netease/musicComments/wordcloud_bg.jpg mode change 100644 => 100755 README.md mode change 100644 => 100755 V2EX/__init__py mode change 100644 => 100755 WeiBo/__init__.py mode change 100644 => 100755 ZhiHu/Billboard.py mode change 100644 => 100755 ZhiHu/__init__.py diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/36kr/__init__.py b/36kr/__init__.py old mode 100644 new mode 100755 diff --git a/FileHandler/Excel.py b/FileHandler/Excel.py old mode 100644 new mode 100755 diff --git a/FileHandler/README.md b/FileHandler/README.md old mode 100644 new mode 100755 diff --git a/FileHandler/__init__.py b/FileHandler/__init__.py old mode 100644 new mode 100755 diff --git a/Get-Books/__init__.py b/Get-Books/__init__.py old mode 100644 new mode 100755 diff --git a/Get-Books/main.py b/Get-Books/main.py old mode 100644 new mode 100755 diff --git a/Headless/BaiduHot.py b/Headless/BaiduHot.py old mode 100644 new mode 100755 diff --git a/Headless/BaiduSearch.py b/Headless/BaiduSearch.py old mode 100644 new mode 100755 diff --git a/Headless/__init__.py b/Headless/__init__.py old mode 100644 new mode 100755 diff --git a/HistoryToday/_360.py b/HistoryToday/_360.py old mode 100644 new mode 100755 diff --git a/HistoryToday/__init__.py b/HistoryToday/__init__.py old mode 100644 new mode 100755 diff --git a/ITHome/__init__.py b/ITHome/__init__.py old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/NHK/__init__.py b/NHK/__init__.py old mode 100644 new mode 100755 diff --git a/Netease/README.md b/Netease/README.md old mode 100644 new mode 100755 diff --git a/Netease/__init__.py b/Netease/__init__.py old mode 100644 new mode 100755 diff --git a/Netease/musicComments/1454897840/1454897840.html b/Netease/musicComments/1454897840/1454897840.html old mode 100644 new mode 100755 diff --git "a/Netease/musicComments/1454897840/\350\216\253\351\227\256\345\275\222\346\234\237.txt" "b/Netease/musicComments/1454897840/\350\216\253\351\227\256\345\275\222\346\234\237.txt" old mode 100644 new mode 100755 diff --git a/Netease/musicComments/wordcloud_bg.jpg b/Netease/musicComments/wordcloud_bg.jpg old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/V2EX/__init__py b/V2EX/__init__py old mode 100644 new mode 100755 diff --git a/WeiBo/__init__.py b/WeiBo/__init__.py old mode 100644 new mode 100755 diff --git a/ZhiHu/Billboard.py b/ZhiHu/Billboard.py old mode 100644 new mode 100755 diff --git a/ZhiHu/__init__.py b/ZhiHu/__init__.py old mode 100644 new mode 100755 From 6f6990b8d08ecc75170e840383a8091c26ff5eb4 Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 25 Feb 2026 14:09:17 +0800 Subject: [PATCH 26/28] feat: Hidapi set AW720M light color --- Hidapi/AW720M.py | 289 +++++++++++++++++++++++++++++++++++++++++++++++ Hidapi/README.md | 76 +++++++++++++ 2 files changed, 365 insertions(+) create mode 100644 Hidapi/AW720M.py create mode 100644 Hidapi/README.md diff --git a/Hidapi/AW720M.py b/Hidapi/AW720M.py new file mode 100644 index 0000000..81fb415 --- /dev/null +++ b/Hidapi/AW720M.py @@ -0,0 +1,289 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +AW720M 灯光控制(Mac,可不使用虚拟环境) +通过 HID Feature Report 设置 Alienware 鼠标/设备的 RGB 灯光。 +依赖:pip3 install --user hidapi 或 brew install hidapi 后 pip 安装 hidapi +""" + +from __future__ import print_function + +import argparse +import sys +import time + +try: + import hid +except ImportError: + print("请先安装 hidapi:", file=sys.stderr) + print(" 方式一(推荐,无需改系统):pipx run --spec hidapi python3 AW720M.py --list", file=sys.stderr) + print(" 方式二(一次安装):pip3 install --break-system-packages hidapi", file=sys.stderr) + print(" 方式三:python3 -m venv .venv && source .venv/bin/activate && pip install hidapi", file=sys.stderr) + sys.exit(1) + +# 协议常量 +# APIv4:34 字节 Feature Report(OpenRGB Alienware 笔记本/台式) +REPORT_SIZE = 33 +HIDAPI_REPORT_SIZE = REPORT_SIZE + 1 +CMD_SET_COLOR = 0x27 +# APIv7:65 字节 USB Interrupt OUT(Alienware 鼠标,如 AW610M/AW720M,见 alienfx-tools) +APIv7_REPORT_SIZE = 65 +APIv7_CMD_CONTROL = (0x40, 0x10, 0x0c, 0x00, 0x01) # COMMV7_control +APIv7_EFFECT_COLOR = 1 # v7OpCodes[AlienFX_A_Color] +# COMMV7_update:设色后发送以“提交”,否则后续设色可能不生效 +APIv7_CMD_UPDATE = (0x40, 0x60, 0x07, 0x00, 0xc0, 0x4e, 0x00, 0x01) + +# 自动发现时仅按设备名称匹配,VID/PID 完全从枚举结果动态获取,不写死 +NAME_KEYWORDS = ("alienware", "aw720", "g series") + + +def _path_str(d): + p = d.get("path") + if p is None: + return "" + return p.decode("utf-8", errors="replace") if isinstance(p, bytes) else p + + +def _str_lower(d, key): + s = (d.get(key) or "").strip() or "" + if isinstance(s, bytes): + s = s.decode("utf-8", errors="replace") + return s.lower() + + +def _device_name_matches(d, keywords=NAME_KEYWORDS): + """设备厂商或产品名包含任一关键词即视为匹配,用于动态发现。""" + product = _str_lower(d, "product_string") + manufacturer = _str_lower(d, "manufacturer_string") + combined = product + " " + manufacturer + return any(kw in combined for kw in keywords) + + +def list_hid_devices(): + """枚举所有 HID 设备,便于确认 AW720M 的 VID/PID。""" + print("HID 设备列表(VID:PID 路径 厂商 产品):") + print("-" * 60) + for d in hid.enumerate(): + print(" {:04x}:{:04x} {} {} {}".format( + d["vendor_id"], + d["product_id"], + _path_str(d), + (d.get("manufacturer_string") or "").strip() or "-", + (d.get("product_string") or "").strip() or "-", + )) + print("-" * 60) + print("未指定 --vid/--pid 时会按设备名称自动匹配(名称含 Alienware/AW720 等);VID:PID 从枚举动态获取。") + + +def find_target_devices(vid=None, pid=None, name_keywords=None): + """ + 动态查找目标设备,不写死 VID/PID。 + - 若指定了 vid+pid:枚举该 VID:PID 下所有 HID 接口,返回 [(path, vid, pid), ...]。 + - 未指定:枚举全部设备,按厂商/产品名包含关键词匹配,返回匹配项的 path 与枚举得到的 vid/pid。 + 返回 [(path, vid, pid), ...],vid/pid 均来自枚举结果。 + """ + out = [] + for d in hid.enumerate(vid if vid is not None else 0, pid if pid is not None else 0): + v, p = d["vendor_id"], d["product_id"] + if vid is not None and pid is not None: + if v != vid or p != pid: + continue + else: + if not _device_name_matches(d, name_keywords or NAME_KEYWORDS): + continue + out.append((d["path"], v, p)) + return out + + +def send_feature_report(dev, buf): + """发送 HID Feature Report,并做短暂延时避免设备忙。""" + dev.send_feature_report(bytes(buf)) + time.sleep(0.06) + + +def get_feature_report(dev, report_id=0x00, size=HIDAPI_REPORT_SIZE): + """读取 HID Feature Report。""" + return dev.get_feature_report(report_id, size) + + +def set_color_apiv7(dev, r, g, b, zone=0, brightness=0x64, retries=5): + """ + APIv7:65 字节 USB Interrupt OUT,用于 Alienware 鼠标(AW610M/AW720M 等)。 + 先发 control 设色,再发 update 提交;重复 retries 次并加延时,提高“有时有效有时无效”时的成功率。 + """ + # 预建 control 与 update 包,避免重复逻辑 + buf = bytearray(APIv7_REPORT_SIZE) + buf[0] = 0x00 + for i, byte_val in enumerate(APIv7_CMD_CONTROL): + buf[1 + i] = byte_val + buf[5] = APIv7_EFFECT_COLOR + buf[6] = brightness & 0xFF + buf[7] = zone & 0xFF + buf[8] = r & 0xFF + buf[9] = g & 0xFF + buf[10] = b & 0xFF + control_packet = bytes(buf) + + upd = bytearray(APIv7_REPORT_SIZE) + upd[0] = 0x00 + for i, byte_val in enumerate(APIv7_CMD_UPDATE): + upd[1 + i] = byte_val + update_packet = bytes(upd) + + time.sleep(0.05) # 打开设备后稍等再发,避免首包被丢 + for _ in range(retries): + dev.write(control_packet) + time.sleep(0.12) + dev.write(update_packet) + time.sleep(0.12) + + +def set_color_direct(dev, r, g, b, zones=(0,)): + """ + APIv4:34 字节 HID Feature Report,用于部分 Alienware 笔记本/台式。 + 部分设备不回复读取,发送后若读回失败则忽略。 + """ + buf = bytearray(HIDAPI_REPORT_SIZE) + buf[0] = 0x00 + buf[1] = 0x03 + buf[2] = CMD_SET_COLOR + buf[3] = r & 0xFF + buf[4] = g & 0xFF + buf[5] = b & 0xFF + n = len(zones) + buf[6] = (n >> 8) & 0xFF + buf[7] = n & 0xFF + for i, z in enumerate(zones): + if 8 + i < len(buf): + buf[8 + i] = z & 0xFF + send_feature_report(dev, buf) + try: + get_feature_report(dev) + except OSError: + pass + + +def open_device(vid, pid, path=None): + """ + 打开 HID 设备,兼容 hid.Device(新)与 hid.device()(旧)两种 API。 + path 优先;否则用 vid/pid。 + """ + def open_by_path(p): + if hasattr(hid, "Device"): + return hid.Device(path=p) + dev = hid.device() + dev.open_path(p) + return dev + + def open_by_vid_pid(v, p): + if hasattr(hid, "Device"): + return hid.Device(vid=v, pid=p) + dev = hid.device() + dev.open(v, p) + return dev + + if path is not None: + return open_by_path(path) + return open_by_vid_pid(vid, pid) + + +def main(): + ap = argparse.ArgumentParser(description="AW720M / Alienware HID 灯光控制(可不使用虚拟环境)") + ap.add_argument("--list", action="store_true", help="枚举 HID 设备并退出,用于查看 VID/PID") + ap.add_argument("--vid", type=lambda x: int(x, 0), default=None, help="USB Vendor ID(不指定则按设备名称自动发现)") + ap.add_argument("--pid", type=lambda x: int(x, 0), default=None, help="USB Product ID(不指定则按设备名称自动发现)") + ap.add_argument("--no-report-id", action="store_true", help="部分设备不需要 Report ID,当前实现仍带 1 字节") + ap.add_argument("--r", type=int, default=None, metavar="0-255", help="红色") + ap.add_argument("--g", type=int, default=None, metavar="0-255", help="绿色") + ap.add_argument("--b", type=int, default=None, metavar="0-255", help="蓝色") + ap.add_argument("--zone", type=int, default=0, help="灯区索引,默认 0") + args = ap.parse_args() + + if args.list: + list_hid_devices() + return + + r = args.r if args.r is not None else 255 + g = args.g if args.g is not None else 0 + b = args.b if args.b is not None else 0 + r = max(0, min(255, r)) + g = max(0, min(255, g)) + b = max(0, min(255, b)) + + # 动态查找目标设备:未指定 vid/pid 时按名称匹配,vid/pid 一律从枚举结果取 + candidates = find_target_devices(args.vid, args.pid) + if not candidates: + # 仅当用户同时指定了 vid 和 pid 时,再试一次直接按该 ID 打开 + if args.vid is not None and args.pid is not None: + candidates = [(None, args.vid, args.pid)] + else: + print("未找到名称匹配的设备(Alienware/AW720 等)。请运行 python3 AW720M.py --list 查看设备列表,并用 --vid/--pid 指定。", file=sys.stderr) + sys.exit(2) + + # 对每个候选接口都打开并发送设色命令(不只看第一个能打开的),避免枚举顺序导致有时命中 LED 有时没命中 + last_error = None + any_open = False + any_sent = False + for path, vid_open, pid_open in candidates: + dev = None + try: + dev = open_device(vid_open, pid_open, path=path) + any_open = True + except Exception as e: + last_error = e + continue + try: + try: + set_color_apiv7(dev, r, g, b, zone=args.zone) + any_sent = True + except OSError: + try: + set_color_direct(dev, r, g, b, zones=(args.zone,)) + any_sent = True + except OSError: + pass + finally: + if dev is not None: + dev.close() + + # 若按 path 一个都没打开,再试一次仅用 vid/pid 打开 + if not any_open and candidates: + vid_open, pid_open = candidates[0][1], candidates[0][2] + try: + dev = open_device(vid_open, pid_open, path=None) + any_open = True + try: + set_color_apiv7(dev, r, g, b, zone=args.zone) + any_sent = True + except OSError: + try: + set_color_direct(dev, r, g, b, zones=(args.zone,)) + any_sent = True + except OSError: + pass + finally: + dev.close() + except Exception as e: + last_error = e + + if not any_open: + print("无法打开 Alienware 设备:{}".format(last_error), file=sys.stderr) + print("", file=sys.stderr) + print("常见原因与处理:", file=sys.stderr) + print(" 1. macOS 权限:系统设置 → 隐私与安全性 → 输入监控 → 勾选「终端」或你使用的 App。", file=sys.stderr) + print(" 2. 尝试用 sudo 运行:sudo python3 AW720M.py --r 255 --g 0 --b 0", file=sys.stderr) + print(" 3. 关闭 Alienware Command Center、Dell 外设管理等可能占用设备的软件后重试。", file=sys.stderr) + print(" 4. AW720M 请用 USB 线连接(不要仅用蓝牙),再试。", file=sys.stderr) + print(" 5. macOS 可能独占鼠标的 HID 接口,导致无法打开;可尝试在 Windows 或 Linux 下用本脚本。", file=sys.stderr) + if not candidates or candidates[0][0] is None: + print(" 6. 运行 python3 AW720M.py --list 查看本机 HID 设备,用 --vid/--pid 指定你的设备。", file=sys.stderr) + sys.exit(2) + + if any_sent: + print("已设置灯光 R={} G={} B={}".format(r, g, b)) + else: + print("已向设备各接口发送命令但均写失败;若灯光无变化可尝试关闭 Dell/Alienware 驱动或换 USB 口。", file=sys.stderr) + + +if __name__ == "__main__": + main() diff --git a/Hidapi/README.md b/Hidapi/README.md new file mode 100644 index 0000000..6909c8a --- /dev/null +++ b/Hidapi/README.md @@ -0,0 +1,76 @@ +# AW720M 灯光控制脚本(Mac) + +通过 HID Feature Report 控制 Alienware AW720M 等设备的 RGB 灯光。 + +## 遇到 externally-managed-environment 时(Homebrew Python) + +系统禁止直接 `pip3 install` 时,可用下面任一方式,**无需手动建虚拟环境**。 + +### 方式一:pipx run(推荐,零安装) + +每次用 `pipx run` 自动带好 hidapi,不用激活 venv、不用改系统 Python: + +```bash +cd Hidapi +# 首次使用需安装 pipx:brew install pipx && pipx ensurepath +pipx run --spec hidapi python3 AW720M.py --list +pipx run --spec hidapi python3 AW720M.py --r 255 --g 0 --b 0 +``` + +### 方式二:允许 pip 安装到系统(一次安装,之后直接 python3) + +接受 PEP 668 的覆盖方式,以后可直接 `python3 AW720M.py`: + +```bash +pip3 install --break-system-packages hidapi +cd Hidapi +python3 AW720M.py --list +python3 AW720M.py --r 255 --g 0 --b 0 +``` + +### 方式三:虚拟环境(传统做法) + +```bash +cd Hidapi +python3 -m venv .venv +source .venv/bin/activate +pip install hidapi +python3 AW720M.py --list +python3 AW720M.py --r 255 --g 0 --b 0 +``` + +## 使用 + +```bash +# 枚举本机 HID 设备,确认鼠标的 VID/PID +python3 AW720M.py --list + +# 设置灯光颜色(不写死 VID/PID,按设备名称自动发现;或 --list 后用 --vid/--pid 指定) +python3 AW720M.py --r 255 --g 0 --b 0 +python3 AW720M.py --r 0 --g 255 --b 0 +python3 AW720M.py --r 0 --g 0 --b 255 +``` + +(若用方式一,上述命令前加:`pipx run --spec hidapi`。) + +## 提示「无法打开设备 / open failed」时 + +- 脚本**不写死 VID/PID**,设备 ID 从枚举结果动态获取;名称含 Alienware/AW720 等即会匹配。 +1. **macOS 输入监控权限**:系统设置 → 隐私与安全性 → 输入监控 → 勾选「终端」(或你运行脚本的 App)。 +2. **用 sudo 试一次**:`sudo python3 AW720M.py --r 255 --g 0 --b 0`(若这样能成功,多半是权限问题)。 +3. 关闭 **Alienware Command Center、Dell 外设管理** 等可能占用 HID 的软件后再试。 +4. **AW720M 请用 USB 线连接**(不要仅用蓝牙)再运行脚本。 +5. **macOS 限制**:系统可能独占鼠标的 HID 接口,导致即使用 sudo 仍「open failed」。此时只能在 Windows 或 Linux 下用本脚本控制灯光。 +6. 脚本会遍历所有匹配接口并尝试按 path / 按 vid:pid 打开;若仍失败,可用 `--list` 查看本机 VID:PID 后以 `--vid/--pid` 明确指定。 + +## 参数说明 + +| 参数 | 说明 | +|------|------| +| `--list` | 列出所有 HID 设备(用于查看 VID/PID) | +| `--vid 0xXXXX` | USB Vendor ID(不指定则按设备名称自动发现) | +| `--pid 0xXXXX` | USB Product ID(不指定则按设备名称自动发现) | +| `--r`, `--g`, `--b` | 红/绿/蓝 0–255 | +| `--zone N` | 灯区索引,默认 0 | + +协议参考 OpenRGB 的 Alienware 控制器实现。 From 0960a6cee806243c991cee64062ae5e2bd84ceae Mon Sep 17 00:00:00 2001 From: skillnull Date: Wed, 25 Feb 2026 14:11:28 +0800 Subject: [PATCH 27/28] feat: update readme --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 75403fe..c4d55f8 100755 --- a/README.md +++ b/README.md @@ -83,4 +83,11 @@ - [日本NHK](/NHK/__init__.py) + + +*
+ 通过Hidapi调整外设颜色 + + - [调整外星人AW720M鼠标颜色](/Hidapi/AW720M.py) +
\ No newline at end of file From a7fb8510b0bed43702744921b772887b77edc086 Mon Sep 17 00:00:00 2001 From: skillnull Date: Tue, 19 May 2026 10:03:14 +0800 Subject: [PATCH 28/28] feat: change file name --- V2EX/{__init__py => __init__.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename V2EX/{__init__py => __init__.py} (100%) diff --git a/V2EX/__init__py b/V2EX/__init__.py similarity index 100% rename from V2EX/__init__py rename to V2EX/__init__.py