zoukankan      html  css  js  c++  java
  • 爬虫2 urllib用法

    from urllib import request,parse
    
    # 1.    解析数据
    # 解析一条
    # response = request.urlopen(url='http://httpbin.org/get?username={}'.format(parse.quote('哈哈')))
    # print(response.read())
    # # 解析字典
    # data1 = {
    #     'username':'哈哈',
    #     'pass' : 23564
    # }
    # res = parse.urlencode(data1)
    # print(res)
    
    
    # 2.    模拟请求头
    # headers = {
    #     'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6721.400 QQBrowser/10.2.2243.400',
    #   
     'Referer':'https://www.baidu.com/s?ie=utf-8&wd=%E5%9B%BE%E7%89%87'

    # } # req = request.Request( # url='http://img5.imgtn.bdimg.com/it/u=935292084,2640874667&fm=26&gp=0.jpg', # headers=headers # ) # response = request.urlopen(req) # print(response.read()) # 3. 发送一个get请求 # response = request.urlopen(url='http://httpbin.org/get',timeout=0.1) # 发送一个get请求 # response = request.urlopen(url='http://httpbin.org/get') # print(response.getcode()) #返回码 # print(response.info()) #返回头部信息 # print(response.read()) #返回内容 # response2 = request.urlopen(url='http://httpbin.org/post', # data = b'username=haha&password=12345'
  • 相关阅读:
    命令[46]
    命令[53]
    命令[48]
    命令[43]
    命令[52]
    命令[55]
    命令[41]
    MYSQL[02]大小写问题
    hdu 1811
    hdu 1829
  • 原文地址:https://www.cnblogs.com/cxhzy/p/10241604.html
Copyright © 2011-2022 走看看