[code] python+selenium实现打开一个网页
转载自:
http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html
http://www.testwo.com/blog/6931
在eclipse中输入以下代码:
#!/usr/bin/env python from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys #chrome download url: http://www.xdowns.com/soft/xdowns2009.asp?softid=136971&downid=10&id=138354 #路径要具体到chrome driver exe文件 #否则会出现错误:selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path. chrome_driver_path = "C:\Python27\selenium\webdriver\chromedriver\chromedriver"
driver = webdriver.Chrome(chrome_driver_path)
driver.get("http://baidu.com")
执行代码,可以看到:
百度的网页在chrome中打开。
对于需要输入用户名和密码,然后点击登录按钮的可以使用如下代码:(通过标签属性name查找元素,driver.find_element_by_name)
#Send username and password
elem_username = driver.find_element_by_name("username")
elem_username.send_keys("xxxx")
elem_password = driver.find_element_by_name("password")
elem_password.send_keys("xxxx") driver.find_element_by_name("login").click()
[code] python+selenium实现打开一个网页的更多相关文章
- Python + Selenium +Chrome 批量下载网页代码修改【新手必学】
Python + Selenium +Chrome 批量下载网页代码修改主要修改以下代码可以调用 本地的 user-agent.txt 和 cookie.txt来达到在登陆状态下 批量打开并下载网页, ...
- 从tcp的角度看,打开一个网页到底发生了什么
使用wireshark进行抓包分析:新建表达式过滤器,选择协议,字段,匹配方式,应用就能筛选出想要的数据包. 一个示例:(tcp.srcport == 1523 or tcp.dstport == 1 ...
- python+selenium遍历某一个标签中的内容
一.python+selenium遍历某一个标签中的内容 举个例子:我要获取列表标签<li></li>的内容 根据python+selenium定位到列表整体,使用for循环获 ...
- Python+Selenium+Chrome 的一个案例
第一步,下载chromeDrive:http://npm.taobao.org/mirrors/chromedriver(我下载的是2.43版本的chromedriver_win32.zip) 下载之 ...
- python+selenium+unnitest写一个完整的登陆的验证
import unittest from selenium import webdriver from time import sleep class lonInTest (unittest.Test ...
- 用Java打开一个网页
BareBonesBrowserLaunch.java 从网上无意间看到的一个工具类,意思是打开一个URL,在不同的操作系统都通用. 1.使用 很简单: String url = "http ...
- python+selenium+PhantomJS爬取网页动态加载内容
一般我们使用python的第三方库requests及框架scrapy来爬取网上的资源,但是设计javascript渲染的页面却不能抓取,此时,我们使用web自动化测试化工具Selenium+无界面浏览 ...
- python+selenium,打开浏览器时报selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
有一年多没写web自动化了,今天搭建环境的时候报了一个常见错误,但是处理过程有点闹心,报错就是常见的找不到驱动<selenium.common.exceptions.WebDriverExcep ...
- python 操作浏览器打开指定网页
#! /usr/bin/env python # encoding=utf8 import webbrowser import time webbrowser.open("http://ww ...
随机推荐
- PyCharm字体大小调整
1.点击左上角File----settings----keymap----------搜索increase,选中,increase font size--------再选择enter mouse sh ...
- Asp.Net MVC HttpPost用法
一个Action只能用一个http 特性,例如:HttpPost 不能与HttpGet 或者多个HttpPost重复使用,否则会出错 也可以用 [AcceptVerbs("put" ...
- PYNQ上手笔记 | ① 启动Pynq
现在人工智能非常火爆,一般的教程都是为博硕生准备的,太难看懂了,分享一个非常适合小白入门的教程,不仅通俗易懂而且还很风趣幽默,点☞这里☜进入传送门~ = = = = 我是华丽的分割线 = ...
- 6.源码分析---和dubbo相比SOFARPC是如何实现负载均衡的?
官方目前建议使用的负载均衡包括以下几种: random(随机算法) localPref(本地优先算法) roundRobin(轮询算法) consistentHash(一致性hash算法) 所以我们接 ...
- 学好C/C++编程,走遍天下都不怕
C++这门语言从诞生到今天已经经历了将近30个年头.不可否认,它的学习难度都比其它语言较高.而它的学习难度,主要来自于它的复杂性.现在C++的使用范围比以前已经少了很多,java.C#.python等 ...
- Android buildType混淆代码
[话题引入] ①在Android开发完成,我们会将代码打包成APK文件.选择 菜单栏 Build --> Build APK ②将查看视图切换到 Project 模式,文件夹下有一个debug模 ...
- STM32实现Airplay音乐播放器
AirPlay是苹果公司推出的一套无线音乐解决方案,我们手里的iPhone.iPad甚至是Apple Watch等设备还有电脑上的iTunes都支持AirPlay,但是支持AirPlay功能的音响设备 ...
- 利用DoHome APP和音箱控制继电器通断电实验参考步骤
准备材料: Arduino Uno 一块 Arduino 扩展板 购买链接 DT-06模块一个 购买链接 安卓手机一个 小度音箱一个 继电器模块一个 杜邦线若干 1.DT-0 ...
- AutoCAD二次开发(.Net)之创建图层Layer
//https://blog.csdn.net/qq_21489689?t=1[CommandMethod("CREATELY")] public void CreateLayer ...
- django在启动时抛出Error: [WinError 10013] 以一种访问权限不允许的方式做了一个访问套接字的尝试 解决办法
1.适用场景 在启动某个服务的时候,比如python中django启动的时候8000端口被占用,导致无法启动服务. 2.解决办法 通过命令行找出端口对应的PID进程 C:\Users\micha> ...