#coding:utf-8
import urllib2,cookielib if __name__ == '__main__':
root_url='https://www.baidu.com/'
# 第一种
print "第一种"
response1=urllib2.urlopen(root_url)
print response1.getcode()
print len(response1.read()) #第二种
print "第二种"
request=urllib2.Request(root_url)
response2=urllib2.urlopen(request)
print response2.getcode()
print len(response2.read()) # 第三种
print "第三种"
cj=cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
response3 = urllib2.urlopen(root_url)
print response3.getcode()
print "cookie为:"+str(cj)
print response3.read()

执行结果

最新文章

  1. JavaScript中JSON的处理心得
  2. java获取当前执行文件的路径
  3. NGUI例子Scroll View场景中item添加点击后自动滑到终点
  4. uva331 - Mapping the Swaps
  5. angularjs的一些优化小技巧
  6. 在Android Studio中进行单元测试和UI测试
  7. hdu2102(bfs)
  8. 455. Assign Cookies.md
  9. 智能指针std::weak_ptr
  10. 『2019/3/8 USACO测试 反思与总结』
  11. npm常用命令学习(npm install -D,semver版本规范, npm进行版本管理的最佳实践用法)
  12. Git push 时如何避免出现 "Merge branch 'master' of ..."
  13. Androi:ViewPager
  14. 使用super调用父类的构造方法
  15. Linux系统如何模拟Http的get或post请求?
  16. Android之listview运用(美团美食列表)
  17. Python学习第一弹
  18. C#简单的文件阅读器
  19. iptables 使用场景
  20. iOS ZipArchive文件解压缩

热门文章

  1. 应对ie双外边距,不使用hack
  2. Chrome自带恐龙小游戏的源码研究(一)
  3. 卡特兰数-Catalan数
  4. ArrayList中contains,remove方法返回为false的原因
  5. linux下安装go
  6. Docker入门系列8
  7. 图像处理之log---log算子
  8. cocos2d-x 3.2 for wp8-xaml应用商店提交应用时出现的API错误(不能用CreateEventExA)解决的方法
  9. Elipse clean后无法编译出class文件
  10. 性能测试--测试流程、APDEX、linux性能知识