Skip to content

Commit d3e541c

Browse files
committed
Update according to comments
1 parent d1f5b07 commit d3e541c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

examples/wait_for_entire_page_load/wait_for_entire_page_load.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from agentql.ext.playwright.sync_api import Page
44
from playwright.sync_api import sync_playwright
55

6-
# Yotube video URL to demonstrate the example for loading comments on the video
6+
# Duckduckgo URL to demonstrate the example for loading more videos on the page
77
URL = "https://duckduckgo.com/?q=machine+learning+lectures+mit&t=h_&iar=videos&iax=videos&ia=videos"
88

99
QUERY = """
@@ -18,22 +18,24 @@
1818

1919

2020
def main():
21-
with sync_playwright() as p:
22-
browser = p.chromium.launch(headless=False)
21+
with sync_playwright() as playwright:
22+
browser = playwright.chromium.launch(headless=False)
23+
24+
# Create a new page in the broswer and cast it to custom Page type to get access to the AgentQL's querying API
25+
page: Page = browser.new_page() # type: ignore
2326

24-
# Create a new AgentQL page instance in the browser for web interactions
25-
page: Page = browser.new_page()
2627
page.goto(URL)
2728

2829
for _ in range(2):
29-
# Wait for the page to load (helps to load the additional videos)
30+
# Wait for additional videos to load completely
3031
page.wait_for_page_ready_state()
3132
# Scroll down the page to trigger loading of more videos
3233
page.keyboard.press("End")
3334

35+
# # Use query_data() method to fetch video lists data from the page
3436
response = page.query_data(QUERY)
3537

36-
# Print the first video details
38+
# Print the details of the first video
3739
print(response["videos"][0])
3840

3941
browser.close()

0 commit comments

Comments
 (0)