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. 将序列化成json格式后日期(毫秒数)转成日期格式

    System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaS ...

  2. Java入门第一季学习总结

    一.课程总概 这门课程的学习难度属于入门级别,又由于有c++的基础,所以学习这门课程也是比较轻松的.可以简单地把这门课的学习分为四部分:第一部分,java的介绍(第一章):第二部分,java的数据类型 ...

  3. C++学习笔记-模板

    模板把函数或类要处理的数据类型参数化,表现为参数的多态性,称为类属.模板用于表达逻辑结构相同,但具体数据元素类型不同的数据对象的通用行为. 什么是模板 类属--类型参数化,又称参数模板 使得程序(算法 ...

  4. Array of Doubled Pairs

    Given an array of integers A with even length, return true if and only if it is possible to reorder ...

  5. The Maze

    There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolli ...

  6. Java中的异常处理try catch(第八周课堂示例总结)

    异常处理 使用Java异常处理机制: 把可能会发生错误的代码放进try语句块中. 当程序检测到出现了一个错误时会抛出一个异常对象. 异常处理代码会捕获并处理这个错误. catch语句块中的代码用于处理 ...

  7. Codeforces 1216F. Wi-Fi

    传送门 这个题一眼 $dp$ 就是设 $f[i][0/1]$ 表示我们只考虑前 $i$ 个位置,并且保证覆盖了前 $i$ 个位置,当前位置 选/不选 的最小代价 考虑转移,设题目给出的字符串为 $s$ ...

  8. C#派生类的构造函数

    构造函数的调用顺序是先调用System.Object,再按照层次结构由上向下(基类=>派生类)进行,直到到达编译器要实例化的类为止.在此过程中,每个构造函数都初始化自己类中的字段.编译器先自下而 ...

  9. leetcode 1282. Group the People Given the Group Size They Belong To

    There are n people whose IDs go from 0 to n - 1 and each person belongs exactly to one group. Given ...

  10. 关于redis的几件小事(七)redis缓存雪崩与穿透

    1.缓存雪崩 (1)什么是缓存雪崩 缓存雪崩指的是在同一时刻,缓存大量失效,导致大量的请求直接到了数据库,数据库压力剧增,引起系统崩溃.可能出现的情况有: ①大量的key设置了相同的过期时间,导致在缓 ...