• 反爬虫和模块get post


    urllib模块只能用get

    urllib2模块既有get也有post

    网址url = urllib2.urlopen(‘

    http://www.zhanjibao.com/core/search/player',data = 'nickname=%E9%9B%AA%E5%9F%9F%E6%9E%AB

    ‘)有data表示post请求

    urllib2模块

    request请求是反爬虫

    add—header中要写成字典的形式,用逗号隔开,单引号引起两部分的内容

    req = urllib2.Request('http://www.zhanjibao.com/core/search/player',data = 'nickname=%E9%9B%AA%E5%9F%9F%E6%9E%AB')
    req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0')

     data

    1
    2
    3
    4
    5
    6
    7
    8
    9
    import urllib
    import urllib2
     
    values = {"username":"1016903103@qq.com","password":"XXXX"}
    data = urllib.urlencode(values)
    url = "https://passport.csdn.net/account/login?from=http://my.csdn.net/my/mycsdn"
    request = urllib2.Request(url,data)
    response = urllib2.urlopen(request)
    print response.read()
     

    get

    4
    5
    6
    7
    8
    9
    10
    11
    12
    import urllib
    import urllib2
     
    values={}
    values['username'] = "1016903103@qq.com"
    values['password']="XXXX"
    data = urllib.urlencode(values)
    url = "http://passport.csdn.net/account/login"
    geturl = url + "?"+data
    request = urllib2.Request(geturl)
    response = urllib2.urlopen(request)
    print response.read()
  • 相关阅读:
    终端等级UE Category—4G数据传输流程系列(五)
    4G数据传输流程系列(四)—物理层OFDM、MIMO实现
    4G数据传输流程系列(三)—物理层“从传输块到码字”
    4G网络数据传输流程与速率分析(二)--资源调度
    4G网络数据传输流程与速率分析系列(一)
    G.711 u律;A律 压缩算法
    VLAN IEEE802.1Q
    64B/66B编码
    Operator与优化
    对偶与Proximal
  • 原文地址:https://www.cnblogs.com/ZHANG576433951/p/6049551.html
Copyright © 2020-2023  润新知