File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
examples/wait_for_entire_page_load Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 3
3
from agentql .ext .playwright .sync_api import Page
4
4
from playwright .sync_api import sync_playwright
5
5
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
7
7
URL = "https://duckduckgo.com/?q=machine+learning+lectures+mit&t=h_&iar=videos&iax=videos&ia=videos"
8
8
9
9
QUERY = """
18
18
19
19
20
20
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
23
26
24
- # Create a new AgentQL page instance in the browser for web interactions
25
- page : Page = browser .new_page ()
26
27
page .goto (URL )
27
28
28
29
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
30
31
page .wait_for_page_ready_state ()
31
32
# Scroll down the page to trigger loading of more videos
32
33
page .keyboard .press ("End" )
33
34
35
+ # # Use query_data() method to fetch video lists data from the page
34
36
response = page .query_data (QUERY )
35
37
36
- # Print the first video details
38
+ # Print the details of the first video
37
39
print (response ["videos" ][0 ])
38
40
39
41
browser .close ()
You can’t perform that action at this time.
0 commit comments