0
点赞
收藏
分享

微信扫一扫

Python日志20

晚熟的猫 2022-03-16 阅读 43
python

selenium基础学习总结

一、selenium基本用法

  1. 创建一个浏览器对象

    from selenium.webdriver import Chrome
    b = Chrome()
    
  2. 打开网页

    b.get()
    
  3. 获取网页数据(能获取到的数据一定是网页加载出来数据)

    result = b.page_source 
    

二、selenium控制网页

  1. 自动在输入框中输入内容

    from selenium.webdriver.common.keys import Keys
    
    # 获取页面上的输入框
    search_box = b.find_element_by_id('key')
    
  2. 向输入框中输入内容

    search_box.send_keys('值')
    
  3. 按回车

    search_box.send_keys(Keys.ENTER)
    
  4. 按搜索键

    #a.找到搜索按钮
    search_btn = b.find_element_by_css_selector('.button')
    
    # b.点击按钮
    search_btn.click()
    
举报

相关推荐

python20

python-day20

Python日志6

Python日志12

Python日志14

Python日志8

0 条评论