Use Selenium to save cookie after log on website
来源:互联网 发布:淘宝双节活动 编辑:程序博客网 时间:2024/06/04 01:26
#!/usr/bin/env python
#coding=utf-8
import urllib2
import urllib
import cookielib
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get("https://abc.com/")
time.sleep(3)
driver.maximize_window()
driver.find_element_by_id("user").send_keys("xxxx")
driver.find_element_by_id("password").send_keys("xxxx")
time.sleep(3)
driver.find_element_by_id("submit").click()
#get the session cookie
cookie = [item["name"] + "=" + item["value"] for item in driver.get_cookies()]
print cookie
cookiestr = ';'.join(item for item in cookie)
print cookiestr
print '%%%using the urllib2 !!'
homeurl=driver.current_url
homeurl = "https://abc.com/index.php/apps/ws/products"
print 'homeurl: %s' % homeurl
headers = {'cookie':cookiestr}
req = urllib2.Request(homeurl, headers = headers)
try:
response = urllib2.urlopen(req)
text = response.read()
fd = open('homepage.html', 'w')
fd.write(text)
fd.close()
print '###get home page html success!!'
except:
print '### get home page html error!!'
time.sleep(5)
driver.close()
0 0
- Use Selenium to save cookie after log on website
- Selenium报错Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
- how to open files on MVC3 website
- How to use HttpWebRequest and RegularExpressions to crash website
- Walkaround for Error : An add-on for this website failed to run. When opening Visual C++'s Add Variable Wizard after IE 8 is ins
- use awk to print after/before n lines after match
- Use different port to test different website in apache
- Ways to Save on anti-virus software
- how to use Properties and File to Save Data
- How to install and use selenium
- Use Python to Drive Selenium RC
- Python use Selenium to control the webdriver
- Log on to computer classes
- dup() ---- Linux function dup() to save debug log.
- website access log visualization
- Selenium Webdriver实现BKredcoil website 自动登录测试、Single Sign On(TestNG+ANT+Excel数据驱动)
- How to run Selenium webdriver on IE
- How to save cookie in file for Requests
- kubernetes集群pod使用tc进行网络资源限额
- 求一个数组中子数组中的和的最大值
- 汇编中的字符串操作指令
- 微信支付——扫码支付模式二
- windows下VirtualBox网络配置
- Use Selenium to save cookie after log on website
- Unity3d 判断三角形是顺时针还是逆时针
- [oc实战练习二]程序里面的网络请求
- 休闲数学-汉诺塔
- REST:Atom标准
- jQuery学习心得----第二集:层次选择器和过滤选择器
- WCF中配置文件解析
- CoreText(一):基本用法
- 微信支付——jaspi支付