Python urllib2模块,发送http请求

demo.py(发送http请求):

# coding:utf-8
import urllib2  # 导入


url = "https://www.baidu.com/"

# 发送请求,返回响应对象。
# 如果只传网址url参数,则默认使用get方式请求。
response = urllib2.urlopen(url)
# response = urllib2.urlopen(url, data={"name": "张三"})   # 如果有data参数,会用post方式请求。

# 获取响应体数据
html_str = response.read()

print(html_str)

猜你喜欢

转载自blog.csdn.net/houyanhua1/article/details/85795647
今日推荐