from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
import time
# 创建浏览器对象
web = Chrome()
# 打开浏览器打开网址
web.get("http://lagou.com")
# 找到某个元素点击
el = web.find_element('xpath', '//*[@id="changeCityBox"]/p[1]/a')
el.click() # 点击
time.sleep(1)
web.find_element('xpath', '//*[@id="search_input"]').send_keys('python', Keys.ENTER)
time.sleep(1)
web.find_element('xpath', '//*[@id="openWinPostion"]').click()
time.sleep(1)
web.switch_to.window(web.window_handles[-1]) # 转移到选项卡为-1窗口
job_detail = web.find_element('xpath', '//*[@id="job_detail"]/dd[2]/div').text
print(job_detail)
web.close()
web.switch_to.window(web.window_handles[0])
print(web.find_element('xpath', '//*[@id="openWinPostion"]'))
每日10行代码183:selenium的基本使用
最新推荐文章于 2024-07-31 10:27:45 发布