Skip to content

Commit 7e28edc

Browse files
committed
Add an example of web-scraping Reddit
1 parent a88dc45 commit 7e28edc

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Reddit Search / Bypasses reCAPTCHA."""
2+
from seleniumbase import sb_cdp
3+
4+
search = "reddit+scraper"
5+
url = f"https://www.reddit.com/r/webscraping/search/?q={search}"
6+
sb = sb_cdp.Chrome(url, use_chromium=True)
7+
sb.solve_captcha() # Might not be needed
8+
post_title = '[data-testid="post-title"]'
9+
sb.wait_for_element(post_title)
10+
for i in range(8):
11+
sb.scroll_down(25)
12+
sb.sleep(0.2)
13+
posts = sb.select_all(post_title)
14+
print('*** Reddit Posts for "%s":' % search)
15+
for post in posts:
16+
print("* " + post.text)

0 commit comments

Comments
 (0)