import os,time,threading
from selenium import webdriver
from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.get('http://www.baidu.com')
print(driver.title)
assert "百度" in driver.title # 这是断言,如果有百度关键字就往下执行
selenium = driver.find_element_by_id("kw")#找到百度输入框的id选择器的元素名字
selenium.send_keys("python")#设置要百度的关键字如“python”
selenium.send_keys(Keys.RETURN) #发送请求
print(driver.page_source)#输出请求结果

#以下的是练习,自动忽略就好
"""
options = webdriver.ChromeOptions()
options.add_argument('user-agent="Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://wenku.baidu.com/view/aa31a84bcf84b9d528ea7a2c.html")
#page = driver.find_elements_by_xpath("//div[@class='page']")
#driver.execute_script('arguments[0].scrollIntoView();', page[-1]) #拖动到可见的元素去
#ele=driver.find_element_by_class_name("foldpagewg-text")
#driver.execute_script("arguments[0].scrollIntoView();",ele)#移动到元素element对象的“顶端”与当前窗口的“顶部”对齐 #driver.execute_script("scroll(0,2400)")#大概的拖动 #driver.execute_script("arguments[0].scrollIntoView(false);",ele)#移动到元素element对象的“底端”与当前窗口的“底部”对齐 #driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")#移动到页面最底部
nextpage = driver.find_element_by_class_name("foldpagewg-text")
nextpage.click()
nextpage2 = driver.find_element_by_xpath("//div[@class='pagerwg-button']")
nextpage2.click()
"""
"""
print("process (%s) start.."% os.getpid())
pid = os.fork()
if(pid == 0):
print('I am child process (%s) and my parent is %s'%(os.getpid(),os.getppid()))
else:
print('I (%s) just created a child process (%s)'%(os.getpid(),pid))
"""
# -*- coding: utf-8 -*-
'''
class Person: def __init__(self):
pass def getAge(self):
print(__name__) p = Person()
p.getAge() a=[1,2,4,2,4,5,6,5,7,8,9,0]
b={}
#b=b.fromkeys(a)
#print(b)
c=list(list(set(a)))
print(c)
'''

python3之selenium.webdriver 库练习自动化谷歌浏览器打开百度自动百度关键字的更多相关文章

  1. python3 使用selenium +webdriver打开chrome失败,报错:FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

    提示chrome driver没有放置在正确的路径下 解决方法: 1.chromedriver与chrome各版本及下载地址 驱动的下载地址如下: http://chromedriver.storag ...

  2. jenkins里跑selenium webdriver,Chrome浏览器不能打开&&unknown error: unable to discover open pages

    在windows的cmd里面执行 “python test.py”,毫无问题,浏览器正常打开,测试结果也正常. 问题: 但如果是在jenkins里,选择 “execute windows batch ...

  3. selenium webdriver从安装到使用(python语言),显示等待和隐性等待用法,切换窗口或者frame,弹框处理,下拉菜单处理,模拟鼠标键盘操作等

    selenium的用法 selenium2.0主要包含selenium IDE 和selenium webDriver,IDE有点类似QTP和LoadRunner的录制功能,就是firefox浏览器的 ...

  4. Selenium WebDriver原理(一):Selenium WebDriver 是怎么工作的?

    首先我们来看一个经典的例子: 搭出租车 在出租车驾驶中,通常有3个角色: 乘客 : 他告诉出租车司机他想去哪里以及如何到达那里 对出租车司机说: 1.去阳光棕榈园东门 2.从这里转左 3.然后直行 2 ...

  5. web自动化环境搭建(python+selenium+webdriver)

    本文档以谷歌浏览器为例,故自动化测试环境为下: 自动化工具为:selenium+webdriver 脚本语言为:Python3.X 浏览器:Chrome 系统环境:Win10 编译工具:Pycharm ...

  6. Python3 使用selenium库登陆知乎并保存cookie为本地文件

    Python3 使用selenium库登陆知乎并保存cookie为本地文件 学习使用selenium库模拟登陆知乎,并将cookie保存为本地文件,然后供以后(requests模块)使用,用selen ...

  7. Python3 Selenium WebDriver网页的前进、后退、刷新、最大化、获取窗口位置、设置窗口大小、获取页面title、获取网页源码、获取Url等基本操作

    Python3 Selenium WebDriver网页的前进.后退.刷新.最大化.获取窗口位置.设置窗口大小.获取页面title.获取网页源码.获取Url等基本操作 通过selenium webdr ...

  8. python爬虫笔记----4.Selenium库(自动化库)

    4.Selenium库 (自动化测试工具,支持多种浏览器,爬虫主要解决js渲染的问题) pip install selenium 基本使用 from selenium import webdriver ...

  9. Selenium WebDriver UI对象库

    UI对象库:使用配置文件存储测试页面上的定位和定位表达式,做到定位数据和程序的分离. 第一步:实现工具类Object工具类,供测试程序调用. /** * 使用配置文件存储测试页面上的定位和定位表达式, ...

随机推荐

  1. 转SQLSERVER 会不会自动加锁

    [SQL]提升查询效率与避免LOCK发生nolock: 可能把没有提交事务的数据也显示出来,可能会产生脏读readpast: 会把被锁住的行不显示出来 所有Select加 With (NoLock)解 ...

  2. spring boot密码管理

    1.引入依赖 <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId> ...

  3. docker命令大全与资源汇总

    容器生命周期管理 run  //创建一个新的容器并运行一个命令 start/stop/restart  //启动一个或多个已经被停止的容器:停止一个运行中的容器:重启容器 kill  //杀掉一个运行 ...

  4. python pandas dataframe 读取和写入Oracle

    1.代码:主要写入时表要为小写,否则报错 Could not reflect: requested table(s) not available in Engine from sqlalchemy i ...

  5. 【go进阶】一个简单的go服务器实现

    光阴似箭,日月如梭,在昨天我终于拿到了自己忙活了半个月的工资. 据说在7月25日有一颗小行星掠过地球,如果真的撞上来,估计31号我就不是乐呵呵的了,应该是直接没了. 如下的代码运行起来就是一个微型go ...

  6. 统计学习方法 | 第1章 统计学习方法概论 | np.random.rand()函数

    np.random.rand()函数 语法: np.random.rand(d0,d1,d2……dn) 注:使用方法与np.random.randn()函数相同 作用: 通过本函数可以返回一个或一组服 ...

  7. python-bioInfo-codes-2

    1. _tkinter.TclError: no display name and no $DISPLAY environment variable 解决方案: import matplotlibma ...

  8. linux 使用tmux

    一. 什么是tmux 1.1. tmux 是两个单词的缩写,即“Terminal MultipleXer”,意思是“终端复用器“ 1.2. tmux 结构 1.2.1. tmux主要由三层: < ...

  9. CSS(下)

    目录 CSS(下) CSS属性相关 宽和高 字体属性 背景属性 边框 border-radius display属性 CSS盒子模型 margin外边距 padding内填充 浮动(float) 限制 ...

  10. Dapper多表查询时子表字段为空

    最近在学习使用Dapper时百度了一篇详细使用教程,在做到多表查询的时候,出现如下情况. 使用的SQL如下, SELECT * FROM [Student] AS A INNER JOIN [Juni ...