zoukankan      html  css  js  c++  java
  • selenium 使用初

    安装: pip install selenum 
     
    下载 chromedriver          下载链接: https://chromedriver.chromium.org/downloads
            注意:下载文件要与chrome版本相兼容(可以在Google的帮助中查看Google的版本)
            注意:64位浏览器对应32位chromedriver
     
        **坑 安装版本比匹配的chromedriver 在使用webdriver.Chrome()可以打开浏览器,但是使用get方法访问网站出错
    配置chromedriver:
            将下载的chromedriver放置到python目录 或者放置到chrome的安装目录(优先python目录)
         
    给浏览器设置代理:
    from selenium import webdriver
     
    proxy = '127.0.0.1:808'
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--proxy-server=http://' + proxy)
    chrome = webdriver.Chrome(chrome_options=chrome_options)
    
     
    导包: from selenium import  webdriver 
     
    选择浏览器:webdriver.Chrome()
    访问网页:webdriver.Chrome().get('url')
    返回上一层:webdriver.Chrome().back()
    关闭浏览器:webdriver.Chrome().close()
    最大化:webdriver.Chrome().close()
    获取源码:page_source()
     
    页面源码: webdriver.Chrome().page_source()
     
    获取节点内容:webdriver.find_element_by_xpath().text
    获取节点属性值:webdriver.find_element_by_xpath().get_attribute('属性')
     
    节点选择:
        通过xpath语法选择:webdriver.find_element_by_xpath()
        通过标签选择器选择和模拟点击节点:webdriver.find_element_by_id().click()
    清楚选择节点的内容:chrome.find_element_by_xpath('//*[@id="identify_email"]').clear()
     
  • 相关阅读:
    TCP/IP——IP网络协议简记
    TCP/IP——基础概念简记
    TCP/IP——链路层简记
    linux——(8)数据流重定向、管道命令
    linux——(7)了解shell
    linux——(6)vim与vi
    linux——(5)文件与文件系统的压缩与打包
    linux——(4)磁盘与文件系统管理
    linux——(3)文件与目录管理
    大数据--Spark原理
  • 原文地址:https://www.cnblogs.com/KHZ521/p/13952013.html
Copyright © 2011-2022 走看看