42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from selenium.webdriver import Chrome, Keys # 键盘操作
|
|
from selenium.webdriver.chrome.options import Options
|
|
import time
|
|
from selenium.webdriver.common.by import By
|
|
|
|
|
|
# chrom_dirverpath = 'C:\Users\zy187\IdeaProjects\python\venv\Scripts\chromedriver.exe'
|
|
web = Chrome()
|
|
|
|
option = Options()
|
|
option.add_argument('--disable_blink_features=AutomationControlled')
|
|
|
|
web.get('http://lagou.com')
|
|
|
|
# 找到某个元素,点击它
|
|
test_poet1 = web.find_element(By.XPATH, r'//*[@id="changeCityBox"]/p[1]/a')
|
|
# el = web.find_element_by_xPath('')
|
|
test_poet1.click()
|
|
# 防止不能加载不出来
|
|
time.sleep(1)
|
|
|
|
# 找到输入框,输入内容 +输入回车,点击搜索
|
|
web.find_element(By.XPATH, r'//*[@id="search_input"]').send_keys('python', Keys.ENTER)
|
|
|
|
time.sleep(5)
|
|
# 查找数据内容,获取数据
|
|
al_list = web.find_elements(By.XPATH,'//*[@id="jobList"]/div[1]/div[1]/div[1]/div[1]')
|
|
print(al_list[1].text)
|
|
time.sleep(1000)
|
|
# # 注意,多个数据要用elements
|
|
for al in al_list:
|
|
# 跳转
|
|
al.find_element(By.TAG_NAME,('a')).click()
|
|
# 窗口转换
|
|
|
|
web.switch_to.window(web.window_handles[-1])
|
|
|
|
time.sleep(1)
|
|
|
|
web.close()
|
|
time.sleep(10000)
|