File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77with sync_playwright () as p :
88 browser = p .chromium .connect_over_cdp (endpoint_url )
99 page = browser .contexts [0 ].pages [0 ]
10- search = "reddit+scraper"
11- url = f"https://www.reddit.com/r/webscraping/search/?q={ search } "
12- sb .goto (url )
10+ search = "Reddit Scraping"
11+ sb .goto ("https://www.reddit.com/r/webscraping/" )
1312 sb .solve_captcha () # Might not be needed
14- page .wait_for_timeout (1000 )
13+ sb .click ("faceplate-search-input" )
14+ sb .press_keys ("html" , search + "\n " )
15+ page .wait_for_timeout (2500 )
1516 post_title = '[data-testid="post-title"]'
1617 page .wait_for_selector (post_title )
1718 for i in range (8 ):
1819 sb .scroll_down (25 )
19- sb .sleep (0.2 )
20+ sb .sleep (0.25 )
2021 print ('*** Reddit Posts for "%s":' % search )
2122 items = page .locator (post_title )
2223 for i in range (items .count ()):
Original file line number Diff line number Diff line change 11"""Reddit Search / Bypasses reCAPTCHA."""
22from seleniumbase import sb_cdp
33
4- search = "reddit+scraper"
5- url = f"https://www.reddit.com/r/webscraping/search/?q={ search } "
4+ search = "Reddit Scraping"
65sb = sb_cdp .Chrome (use_chromium = True )
7- sb .goto (url )
6+ sb .goto ("https://www.reddit.com/r/webscraping/" )
87sb .solve_captcha () # Might not be needed
8+ sb .click ("faceplate-search-input" )
9+ sb .press_keys ("html" , search + "\n " )
10+ sb .sleep (2.5 )
911post_title = '[data-testid="post-title"]'
1012sb .wait_for_element (post_title )
1113for i in range (8 ):
1214 sb .scroll_down (25 )
13- sb .sleep (0.2 )
15+ sb .sleep (0.25 )
1416posts = sb .select_all (post_title )
1517print ('*** Reddit Posts for "%s":' % search )
1618for post in posts :
Original file line number Diff line number Diff line change 22from seleniumbase import SB
33
44with SB (uc = True , test = True , use_chromium = True ) as sb :
5- search = "reddit+scraper "
6- url = f"https://www.reddit.com/r/webscraping/search/?q= { search } "
7- sb .activate_cdp_mode ( url )
5+ search = "Reddit Scraping "
6+ sb . activate_cdp_mode ()
7+ sb .goto ( "https://www.reddit.com/r/webscraping/" )
88 sb .solve_captcha () # Might not be needed
9+ sb .click ("faceplate-search-input" )
10+ sb .press_keys ("html" , search + "\n " )
11+ sb .sleep (2.5 )
912 post_title = '[data-testid="post-title"]'
1013 sb .wait_for_element (post_title )
1114 for i in range (8 ):
1215 sb .scroll_down (25 )
13- sb .sleep (0.2 )
16+ sb .sleep (0.25 )
1417 posts = sb .select_all (post_title )
1518 print ('*** Reddit Posts for "%s":' % search )
1619 for post in posts :
Original file line number Diff line number Diff line change 33
44
55async def main ():
6- search = "reddit+scraper"
7- url = f"https://www.reddit.com/r/webscraping/search/?q={ search } "
6+ search = "Reddit Scraping"
87 driver = await cdp_driver .start_async (use_chromium = True )
9- page = await driver .get (url )
8+ page = await driver .get ("https://www.reddit.com/r/webscraping/" )
109 await page .solve_captcha () # Might not be needed
10+ element = await page .find ("faceplate-search-input" )
11+ await element .mouse_click_async ()
12+ await page .type ("html" , search + "\n " )
13+ await page .sleep (2.5 )
1114 post_title = '[data-testid="post-title"]'
1215 await page .select (post_title )
1316 for i in range (8 ):
You can’t perform that action at this time.
0 commit comments