python 请求url-api总结[写爬虫基础]

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:02   1065   0

requests库:

get请求:

second_html = requests.get(sel_url, headers=headers)
Soup2 = BeautifulSoup(second_html.text,"html.parser")

post json请求:

res = requests.post(url,data=json.dumps(values),headers={'Content-Type':'application/json'})
print(res.json())

通过session,进行get、post请求:

session = requests.Session()
data = session.get(geoUrl, timeout=1)
data.json

#构造Session
session = requests.Session()

#在session中发送登录请求,此后这个session里就存储了cookie
#可以用print(session.cookies.get_dict())查看
resp = session.post(login_url, data)

urllib2库:

data = urllib2.urlopen(geoUrl)
hjson = json.loads(data.read()) # json对象转成python对象

get请求post请求session
requests库requests.get
返回res.json();
requests.post(json类型)
获取session,通过session post和get
urllib2库urlopen.urllib2
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP