1. 程式人生 > >selenium的基本用法

selenium的基本用法

一.配置連線

1.一般連線

from selenium import webdriver
bro = webdriver.Firefox(executable_path = 'D:\APPS\dir\geckodrive
bro.get('https://cdn-img.comic-days.com/public/page/2/10834108156629381635-b8eabac8eb15999292782ed222a2610b')
print(bro.page_source)

2.無頭連線

fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.set_headless()
bro1 = webdriver.Firefox(firefox_options=fireFoxOptions,executable_path = '/home/nidengke/utils/geckodriver'
) bro2 = webdriver.Firefox(firefox_options=fireFoxOptions,executable_path = '/home/nidengke/utils/geckodriver') bro3 = webdriver.Firefox(firefox_options=fireFoxOptions,executable_path = '/home/nidengke/utils/geckodriver') bro.get('https://koubei.baidu.com/rank?tid=1101') print(bro.page_source)

3.查詢方法

bro.find
_element_by_xpath() xpath查詢 bro.find_element_by_css_seletor()