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的更多相关文章

  1. 《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 ...

  2. Python Web-第二周-正则表达式(Using Python to Access Web Data)

    0.课程地址与说明 1.课程地址:https://www.coursera.org/learn/python-network-data/home/welcome 2.课程全名:Using Python ...

  3. 【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 ...

  4. 【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 ...

  5. 《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 ...

  6. 《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 ...

  7. 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 ...

  8. paip. 解决php 以及 python 连接access无效的参数量。参数不足,期待是 1”的错误

    paip. 解决php 以及 python 连接access无效的参数量.参数不足,期待是 1"的错误 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源 ...

  9. Transferring Data Between ASP.NET Web Pages

    14 July 2012 20:24 http://www.mikesdotnetting.com/article/192/transferring-data-between-asp-net-web- ...

随机推荐

  1. Object类—复写equals方法,hashCode方法,toString方法

    Object:所有类的根类. Object是不断抽取而来,具备着所有对象都具备的共性内容. class Person extends Object { private int age; Person( ...

  2. event模拟数据库链接

    from threading import Thread,Event,currentThread import time e = Event() def conn_mysql(): count = 1 ...

  3. 机器学习算法实践:Platt SMO 和遗传算法优化 SVM

    机器学习算法实践:Platt SMO 和遗传算法优化 SVM 之前实现了简单的SMO算法来优化SVM的对偶问题,其中在选取α的时候使用的是两重循环通过完全随机的方式选取,具体的实现参考<机器学习 ...

  4. 深入Javascript之this

    前言 近期准备好好的读一读<你不知道的JavaScript(上卷)>这本书,俗话说的好,好记性不如烂笔头,读到this这章感觉是时候需要一些笔记了.文中如有错误之处,欢迎指出. 什么是th ...

  5. Tomcat针对网站打开速度慢进行局部优化方案

    首先打开tomcat下的conf文件夹里面的server.xml找到Tomcat端口号一栏 <Connector port="8081" protocol="HTT ...

  6. APUE 4 - 线程<2> : 线程同步

    当控件的多个线程共享统一内存时,我们需要确定各个线程访问到的数据的一致性.在cpu结构中,修改操作由多个内存读写周期(memory cycle),而在这些内存周期之间, 有可能会发生其他线程的内存读操 ...

  7. 大道至简第一章读后感Java伪代码

    //一.愚公移山 /*原始需求 惩山北直塞,出入之迁也. 项目沟通的方式 聚室而谋 项目目标 毕力平险,指通豫南,达于汉阴 人员组成 愚公,子孙荷担者三夫,邻人遗男 技术方案 叩石垦壤 簸萁运与渤海之 ...

  8. LeetCode 88. Merge Sorted Array(合并有序数组)

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...

  9. Java常用类(五)之集合工具类Collections

    前言 Java提供了一个操作Set.List和Map等集合的工具类:Collections,该工具类提供了大量方法对集合进行排序.查询和修改等操作, 还提供了将集合对象置为不可变.对集合对象实现同步控 ...

  10. 找到python官方标准库文档

    python中有很多标准库.我们没法记住全部标准库,但是可以在:https://docs.python.org/3/py-modindex.html 中查看标准库的索引 在python的官方文档中,如 ...