forked from MorvanZhou/easy-scraping-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5-1-selenium.py
24 lines (20 loc) · 925 Bytes
/
5-1-selenium.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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# firefox plugin
# https://askubuntu.com/questions/870530/how-to-install-geckodriver-in-ubuntu
# hide browser window
chrome_options = Options()
chrome_options.add_argument("--headless") # define headless
# add the option when creating driver
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://morvanzhou.github.io/")
driver.find_element_by_xpath(u"//img[@alt='强化学习 (Reinforcement Learning)']").click()
driver.find_element_by_link_text("About").click()
driver.find_element_by_link_text(u"赞助").click()
driver.find_element_by_link_text(u"教程 ▾").click()
driver.find_element_by_link_text(u"数据处理 ▾").click()
driver.find_element_by_link_text(u"网页爬虫").click()
print(driver.page_source[:200])
driver.get_screenshot_as_file("./img/sreenshot2.png")
driver.close()
print('finish')