python urllib简单用法
来源:互联网 发布:纺织设计软件 编辑:程序博客网 时间:2024/06/06 07:24
#!/usr/bin/env python# -*- coding: UTF-8 -*-from urllib.request import Requestfrom urllib.request import urlopenfrom urllib import parse##简单获取网页源码#html = urlopen("http://www.baidu.com")#打开链接#print(html.read().decode("utf-8"))#返回UTF-8编码的网站源码##模拟发送POST请求#req = Request("http://xxx.xxxx.com/apitest/userapi.php?act=addsheji")##postData = parse.urlencode([#("name","str1"),#("tel","str2"),#("mac","str3")#])##req.add_header("Origin","http://www.baidu.com") #请求头部 添加来源#req.add_header("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36")#resp = urlopen(req,data=postData.encode('utf-8'))##print(resp.read().decode("utf-8"))##带请求参数获取网页源码的方法#发起请求req = Request("http://www.baidu.com")#添加请求参数req.add_header("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36")#打开链接resp = urlopen(req)#返回UTF-8编码的网站源码print(resp.read().decode("utf-8"))
阅读全文
0 0
- python urllib简单用法
- python 下载 保存 图片的urllib.urlretrieve()函数 简单用法
- Urllib.request用法简单介绍(Python3.3)
- python爬虫入门-urllib的基本用法
- python中urllib的高级用法
- 【Python】urllib的基本用法01
- python中urllib库简单使用
- Python爬虫之urllib简单使用
- Python爬虫之urllib简单下载内容
- urllib用法
- python urllib
- python urllib
- python urllib
- python urllib
- Python urllib
- Python urllib
- python urllib
- 【python】urllib
- 常用 Git 命令清单
- 静态属性和静态方法
- java静态内部类与普通内部类
- jQuery-checkbox
- PHPStrom中实用的功能和快捷键大全
- python urllib简单用法
- MyBatis
- Android 设备 USB 通用调试驱动的安装方法
- Bzoj4553: Tjoi2016&Heoi2016-序列
- android studio生成签名sha1值,MD5值
- MyEclipse的Log4j简单配置
- 《shell脚本学习指南》学习笔记之入门 一
- android如何修改手机连接电脑显示在电脑上的名字(MTK)
- Numerical Summation of a Series