gaoqilan commited on
Commit
0b98038
·
verified ·
1 Parent(s): c7bd724

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from playwright.sync_api import sync_playwright
2
+ import os, time, random
3
+
4
+ def auto_read():
5
+ with sync_playwright() as p:
6
+ browser = p.chromium.launch()
7
+ page = browser.new_page()
8
+
9
+ # 登录
10
+ page.goto("https://linux.do/login")
11
+ page.type("#username", os.getenv("USERNAME"))
12
+ page.type("#password", os.getenv("PASSWORD"))
13
+ page.click("button.login-button")
14
+ time.sleep(3)
15
+
16
+ # 自动阅读
17
+ while True:
18
+ page.goto("https://linux.do/latest")
19
+ links = page.query_selector_all("a.topic-title")
20
+ for link in links[:5]:
21
+ page.goto(link.get_attribute("href"))
22
+ page.mouse.wheel(0, random.randint(200,500))
23
+ time.sleep(random.uniform(1.5,4))
24
+ time.sleep(random.randint(600, 1200)) # 10-20分钟间隔
25
+
26
+ if __name__ == "__main__":
27
+ auto_read()