-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect_bilibili.py
More file actions
40 lines (34 loc) · 1.72 KB
/
inspect_bilibili.py
File metadata and controls
40 lines (34 loc) · 1.72 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
from playwright.sync_api import sync_playwright
def inspect_bilibili():
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp("http://localhost:9222")
context = browser.contexts[0]
bili_page = None
for page in context.pages:
if "jobs.bilibili.com" in page.url:
bili_page = page
break
if bili_page:
print("Found Bilibili page.")
bili_page.bring_to_front()
body_text = bili_page.evaluate("""() => document.body.innerText.substring(0, 1000)""")
print("Body Text excerpt:")
print(body_text)
# Print all button tags and some context
pagination_html = bili_page.evaluate("""() => {
const els = document.querySelectorAll('button, li, a, div[class*="page"]');
return Array.from(els).filter(e => e.innerText.includes('下一页') || e.innerText.includes('页') || e.className.includes('next') || e.className.includes('page')).map(e => e.outerHTML).slice(0, 5).join('\\n');
}""")
print("Next button HTML:")
print(pagination_html)
# Print recently intercepted requests
requests = bili_page.evaluate("""() => {
const entries = performance.getEntriesByType('resource');
return entries
.filter(r => r.name.includes('api') || r.name.includes('position') || r.name.includes('job') || r.name.includes('list'))
.map(r => r.name).join('\\n');
}""")
print("Recent API Requests:")
print(requests)
if __name__ == "__main__":
inspect_bilibili()