• post请求get请求


    1. post请求
      # _*_ coding::utf_8 _*_
      import urllib.request
      import urllib.parse
      # 开始url、(word、data在一块)headers请求头
      post_url='https://fanyi.baidu.com/sug'
      word=input('输入查询单词:')
      form_data={
          'kw':word,
      }
      headers={
      'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
      }
      #对data进行encode()操作,urlencode
      form_data=urllib.parse.urlencode(form_data).encode()
      # 伪装
      url=urllib.request.Request(url=post_url,headers=headers)
      #post请求中要加入data值
      response=urllib.request.urlopen(url,data=form_data)
      #输出post
      print(response.read().decode())
    2. get请求
      # _*_ coding:utf_8 _*_
      import urllib.request
      import urllib.parse
      content=input("输入要搜索的内容:")
      url='https://www.baidu.com/s?tn=93288632_hao_pg&ie=utf-8&sc=UWY4n1c3rjm1n-qCmyqxTAThIjYkPHm4nHRYPHcYP1bzFhnqpA7EnHc1Fh7W5HnLPH64rHRkPjT&ssl_sample=normal&srcqid=3499612321700897328&H123Tmp=nunew7&'
      data={
         'word':content
      }
      query_string=urllib.parse.urlencode(data)
      url=url+query_string
      response=urllib.request.urlopen(url)
      filename=content+'.html'
      with open(filename,'wb') as fp:
          fp.write(response.read())
  • 相关阅读:
    bzoj1562: [NOI2009]变换序列
    bzoj2763: [JLOI2011]飞行路线
    有上下界网络流
    bzoj3211: 花神游历各国
    bzoj3668: [Noi2014]起床困难综合症
    bzoj2743: [HEOI2012]采花
    BZOJ 1787: [Ahoi2008]Meet 紧急集合
    BZOJ 1029 [JSOI2007]建筑抢修 贪心
    BZOJ 2748 音量调节
    BZOJ 3524: [Poi2014]Couriers 主席树
  • 原文地址:https://www.cnblogs.com/ybl20000418/p/11575265.html
Copyright © 2020-2023  润新知