zoukankan      html  css  js  c++  java
  • python__标准库 : urllib2

    urllib,urllib2

    urllib库主要用 urlencode()把字典转换成url的get参数或者post参数 或者用 quote() 进行编码unquote进行解码

    用urllib2.ProxyHandler(proxy_list)创建代理处理器,urllib2.HTTPHandler创建正常处理器
    (proxy_list = {"http":"x.x.x.x:80"} 代理是这种格式)

    opener = urllib2.build_opener(handler)这样创建opener

    request = urllib2.Request(url,data,headers)用这个创建访问请求

    opener.open(request)发送请求(或者urllib2.install_opener(opener)这样之后,全局的urlopen就都
    可以用自定义的opener发送请求了,直接用urlopen就可以了)

    使用cookielib.CookieJar() 来存储cookie,使用urllib2.HTTPCookieProcessor(CookieJar) 来构建带cookie的handler

    -----------------------------------------------------------------------------------------------------------

    用 requests.Session() 来创建一个session对象,用它get或者post可以保存cookie.

    lxml:把html转换成html dom模型 :

    from lxml import etree

    response = request.get().text()

    dom = etree(response)

    dom.xpath() 这样就可以用xpath去提取数据,返回列表.

  • 相关阅读:
    Django之form组件
    Http协议
    用户认证系统 django.contrib.auth模块
    自己关于Django的一些实践
    form标签
    jquery 遍历find()与children()的区别
    存储过程
    ASP.NET优化
    TRUNCATE与 DELETE
    视图的作用
  • 原文地址:https://www.cnblogs.com/cccy0/p/9496512.html
Copyright © 2011-2022 走看看