zoukankan      html  css  js  c++  java
  • 第八节 request发送get请求和post请求

     1 import requests
     2 kw = {'wd':"中国"}
     3 headers = {
     4     "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
     5 }
     6 resp = requests.get('http://www.baidu.com/s',params=kw, headers=headers)
     7 print(type(resp.content))#返回的源代码以二进制储存
     8 print(type(resp.text))#将上面的数据自行解码后的数据,但是经常会出现乱码,一般自行解码
     9 print(resp.content.decode('utf-8'))
    10 print(resp.url)#返回网址
    11 print(resp.encoding)#返回编码方式
    12 print(resp.status_code)#响应状态码
     1 import requests
     2 import json
     3 
     4 
     5 headers = {
     6     "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36",
     7     "Referer":"https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput="
     8 }
     9 data = {
    10     "first":"true",
    11     "pn":1,
    12     "kd":"python"
    13 }
    14 resp = requests.post("https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput=",data=data,headers=headers)
    15 print(resp.text)
  • 相关阅读:
    Winform架构
    SQL2008多数据库查询表或删表
    hdu1114 PiggyBank
    hdu2844 Coins
    hdu2602 Bone Collector
    hdu2191 珍惜现在
    hdu1203 I NEED A OFFER!
    求推荐
    TransparentBlt
    双缓冲加载位图 WinCE
  • 原文地址:https://www.cnblogs.com/kogmaw/p/12506926.html
Copyright © 2011-2022 走看看