-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlisting_structure.py
More file actions
41 lines (37 loc) · 1.55 KB
/
listing_structure.py
File metadata and controls
41 lines (37 loc) · 1.55 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
41
from playwright.sync_api import sync_playwright
import json
def get_listing_structure():
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
url = "http://www.parliament.go.ke/the-national-assembly/house-business/bills"
page.goto(url, wait_until="networkidle")
# Get all rows in the view-content
rows = page.evaluate("""() => {
const results = [];
// Try different containers
const containers = document.querySelectorAll('.view-content, .field-items, tbody, .item-list');
containers.forEach(container => {
const items = container.querySelectorAll('.views-row, tr, li');
items.forEach((item, i) => {
if (i > 15) return; // Limit to first 15
const links = Array.from(item.querySelectorAll('a')).map(a => ({
text: a.textContent.trim(),
href: a.href,
html: a.outerHTML
}));
if (links.length > 0) {
results.push({
index: i,
text: item.textContent.trim().substring(0, 100),
links: links
});
}
});
});
return results;
}""")
print(json.dumps(rows, indent=2))
browser.close()
if __name__ == "__main__":
get_listing_structure()