Python crawler access to web pages the get requests a cookie

Python in the process of accessing the web page,encounter with cookie,so we need to get it.
cookie in Python is form of a dictionary exists ,so cookie is {'cookie':'cookies'}
get cookie need webdriver(),Several browsers/drivers are supported (Firefox, Chrome, Internet Explorer, PhantomJS), as well as the Remote protocol.
from selenium import webdriver
Definition function,Because cookie in requests headers.so:
headers={}
if headers.get('cookie'):
'No!'
else:
'YES!'
Definition function:
def p(url,header):
if header.get('cookie'):
print 'YES!'
else:
print 'NO!'
headers = {}
driver=webdriver.Chrome()
driver.get(url)
cookie=driver.get_cookies()
#print cookie
s = []
for i in cookie:
lt.append(i.get('value'))
s.append(i.get('name') + "=" +i.get('value') )
#print s
#headers['cookie'] = ','.join(s) # if headers.get('cookie')
header.update(headers) # if no headers.get('cookie')
driver.quit()
p(url,header) #xiuluo
Interface ~:
if __name__ == '__main__':
header={'data':'dasda'}
url = ''
p(url,header)
If there is no entry, the function will not be executed ~~!!
Python crawler access to web pages the get requests a cookie的更多相关文章
- 《Using Python to Access Web Data》Week4 Programs that Surf the Web 课堂笔记
Coursera课程<Using Python to Access Web Data> 密歇根大学 Week4 Programs that Surf the Web 12.3 Unicod ...
- Python Web-第二周-正则表达式(Using Python to Access Web Data)
0.课程地址与说明 1.课程地址:https://www.coursera.org/learn/python-network-data/home/welcome 2.课程全名:Using Python ...
- 【Python学习笔记】Coursera课程《Using Python to Access Web Data》 密歇根大学 Charles Severance——Week6 JSON and the REST Architecture课堂笔记
Coursera课程<Using Python to Access Web Data> 密歇根大学 Week6 JSON and the REST Architecture 13.5 Ja ...
- 【Python学习笔记】Coursera课程《Using Python to Access Web Data 》 密歇根大学 Charles Severance——Week2 Regular Expressions课堂笔记
Coursera课程<Using Python to Access Web Data > 密歇根大学 Charles Severance Week2 Regular Expressions ...
- 《Using Python to Access Web Data》 Week5 Web Services and XML 课堂笔记
Coursera课程<Using Python to Access Web Data> 密歇根大学 Week5 Web Services and XML 13.1 Data on the ...
- 《Using Python to Access Web Data》 Week3 Networks and Sockets 课堂笔记
Coursera课程<Using Python to Access Web Data> 密歇根大学 Week3 Networks and Sockets 12.1 Networked Te ...
- Displaying Data in a Chart with ASP.NET Web Pages (Razor)
This article explains how to use a chart to display data in an ASP.NET Web Pages (Razor) website by ...
- paip. 解决php 以及 python 连接access无效的参数量。参数不足,期待是 1”的错误
paip. 解决php 以及 python 连接access无效的参数量.参数不足,期待是 1"的错误 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源 ...
- Transferring Data Between ASP.NET Web Pages
14 July 2012 20:24 http://www.mikesdotnetting.com/article/192/transferring-data-between-asp-net-web- ...
随机推荐
- win10 uwp 验证输入 自定义用户控件
TextBox是给用户输入,我们有时要用户只输入数字,而用户输入汉字,我们就有提示用户,那么这东西用到次数很多,我们需要做成一个控件. 我们可以用别人的库,我找到一个大神写的库,很好用 我们使用这个库 ...
- UVa11882,Biggest Number
搜索+剪枝 如此水的一个题,居然搞了一上午 出错在bfs与dfs时共用了一个vis数组,导致bfs完后返回dfs应该能访问到的点访问不到 自己想怎么剪枝,想了几个剪枝方法,又证明,又推翻,再想,再证明 ...
- Python装饰器,json,pickle
装饰器 定义:本质是函数,装饰其它函数是为了给其添加新功能: 原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 实现装饰器知识储备: 1.函数即变量: 2.高阶函数 3.嵌套 ...
- Docker部属Nsq集群
用一了段时间NSQ还是很稳定的.除了稳定,还有一个特别值的说的就是部署非常简单.总想写点什么推荐给大家使用nsq来做一些东西.但是就是因为他太简单易用,文档也比较简单易懂.一直不知道要写啥!!!!! ...
- (转)spring事务管理几种方式
转自:http://blog.csdn.net/jeamking/article/details/43982435 前段时间对Spring的事务配置做了比较深入的研究,在此之间对Spring的事务配置 ...
- 处理MySQL服务器无法启动的问题
MySQL数据库在升级到5.7版本后,和之前的版本有些不一样,没有data文件夹,我们都知道MySQL数据库文件是保存在data文件夹中的,网上有人说把5.6版本的data文件夹拷贝一个,这种说法听听 ...
- HTML5的Websocket(理论篇 I)
HTML5的Websocket(理论篇 I) ** 先请来TA的邻居:** http:无状态.基于tcp请求/响应模式的应用层协议 (A:哎呀,上次你请我吃饭了么? B:我想想, 上次请你吃了么) t ...
- LeetCode 191. Number of 1 bits (位1的数量)
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- centos7 最小安装无ifconfig
可能不会有人看到这篇文章,加入有幸被看到,建议读者从后往前看!最小化安装问题:1 没有ifconfig 命令,解决:yum install net-tools2 使用yum install n ...
- celery rabbit mq 详解
Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celery, ...