-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
31 lines (23 loc) · 1.01 KB
/
test.py
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
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
# Set the options we want. In this case headless
options = Options()
options.headless = True
driver = webdriver.Firefox(executable_path=r'C:\WebDrvTools\bin\geckodriver.exe', options=options)
with driver:
driver.get("https://www.reddit.com/")
search = driver.find_element(By.NAME, "q")
search.send_keys("scraping")
search.send_keys(Keys.ENTER)
search_results = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CLASS_NAME, "rpBJOHq2PR60pnwJlUyP0"))
)
posts = search_results.find_elements_by_css_selector("h3._eYtD2XCVieq6emjKBH3m")
for post in posts:
header = post.find_element_by_tag_name("span")
print(header.text)