• 爬虫——利用request来post博客园和百度


    博客园:

    #! /usr/bin/env python
    #coding:utf-8

    import sys
    import re
    import urllib2
    import urllib
    import requests
    import cookielib

    url='http://httpbin.org/post'
    payload = {"yoyoketang":"lalala",

        "python":"hello"}
    r = requests.post(url, data=payload)
    print r.text
    print r

    百度:

    #coding:utf-8

    import requests
    import json,time
    url = "https://passport.baidu.com/"

    headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0",

        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",

        "Accept-Language": "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",

        "Accept-Encoding": "gzip, deflate",

        "Referer": "https://passport.baidu.com/v2/?login",

        "Cookie":# 此处省略

        "Connection": "keep-alive",
        "Host":"passport.baidu.com"

    }

    payload={"input1":"9681BD43724DDB023260051E3B9520A027631E5E200675AAB90D8322FC4935DAB06DFB10D3C4A4C9EC65F589C6A0EE505F001408CFFDCCAC6B7962E4B7E  9908685474397591935B1AEB2AADCDBEFDFE05AE16AB1",

      "input2":"CfDJ8Gf3jjv4cttDnEy2UYRcGZ3bsShXX0DA1mccKNUsjZHITE6cjgfFXlPLtU87HDk5TTW2FVwdTjVFcRXuWXJ7VfvjW4m7xFXQlhPkPPwP",

      "remember":True}

    r = requests.post(url, data=payload, headers=headers,verify=False)
    time.sleep(3)

    print r.text
    print 'code:',r

  • 相关阅读:
    css侧边栏之综合实例3
    css侧边栏之综合实例2
    css实例之侧边栏
    css实例之正文
    css之使用 | margin | padding
    css之链接 | 点击后变色 | 悬停 | hover
    1.2(Mybatis学习笔记)Mybatis核心配置
    1.1(Mybatis学习笔记)初识Mybatis
    1.1(Spring学习笔记)Spring-事务基础
    1.4(Spring学习笔记)Spring-JDBC基础
  • 原文地址:https://www.cnblogs.com/garvicker/p/9414788.html
Copyright © 2020-2023  润新知