-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
36 lines (31 loc) · 1.04 KB
/
demo.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
32
33
34
35
36
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.techwithtim.net")
print(driver.title)
search = driver.find_element_by_name("s")
search.send_keys("test")
search.send_keys(Keys.RETURN)
# print(driver.page_source)
# time.sleep(5)
try:
main = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "main"))
)
# print(main.text)
articles = main.find_elements_by_tag_name("article")
for article in articles:
header = article.find_element_by_class_name("entry-summary")
print(header.text)
# except:
finally:
driver.quit()
# main=driver.find_element_by_id("main")
# print(main.text)
driver.quit()