• 爬虫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'
  • 相关阅读:
    clone对象
    Windows下swoole扩展的编译安装部署
    PHP备忘录
    Linux文档的压缩与打包
    Linux系统启动过程
    Linux虚拟机安装
    MongoDB自动增长
    MongoDB固定集合(Capped Collections)
    Activating Google Cloud Storage
    Downloading the Google Cloud Storage Client Library
  • 原文地址:https://www.cnblogs.com/cxhzy/p/10241604.html
Copyright © 2020-2023  润新知