selenium安装及最简示例
### 包安装
#### selenium安装
pip install selenium
#### phantomjs安装
* 下载地址:[phantomjs-2.1.1-windows.zip](https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-windows.zip)
* 将phantomjs.exe所在路径添加到系统PATH
### 遇到的问题:
selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH.
### 解决办法:
1. 确认phatomjs所在路径添加到系统变量PATH
2. 将文件放到Python的Scripts目录
3. 调用时使用全路径,如下所示
drive = webdriver.PhantomJS(executable_path="C:\\Users\\Administrator\\Desktop\\phantomjs.exe")
### 补充:
1. 如果用到了FireFox,需要geckodriver,处理方法同上。
2. 下载下来并放以系统可识别的目录
### 代码示例1:访问QQ空间,打印标题
from selenium import webdriver
drive = webdriver.PhantomJS()
drive.get('http://qzone.qq.com')
print(drive.title)
### 代码示例2:访问道客88,自动登录系统
# coding:utf-8
from selenium import webdriver
import time
# 启动火狐
broswer = webdriver.Firefox()
# 访问doc88
broswer.get("http://www.doc88.com/")
# 点击登录
broswer.find_element_by_class_name("login").click()
time.sleep(1)
# 切换fram
# broswer.switch_to_frame("doc88Window")
broswer.switch_to.frame("doc88Window")
broswer.find_element_by_class_name("textcss1").send_keys("yourusername")
time.sleep(1)
broswer.find_element_by_id("password").send_keys("yourpasswd")
time.sleep(1)
# broswer.find_element_by_id("btn_1501657659123").drag_and_drop_by_offset(self, source, 0,10)
# 点击登录
broswer.find_element_by_class_name("btncss1").click()
# 关闭浏览器
broswer.quit()
文章最后更新时间:
2017年08月03日 12:26:31
заявление об уничтожении крыс
кротов уничтожение
виза в индию в екатеринбурге быстро
I do not even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you're going to a famous blogger if you are not already
Asking questions are actually pleasant thing if you are nnot understanding anything completely, but this post provides nice understanding even. webpage bet match betting