手机
当前位置:查字典教程网 >脚本专栏 >python >python中mechanize库的简单使用示例
python中mechanize库的简单使用示例
摘要:复制代码代码如下:#!/usr/bin/env/python#coding=utf-8importmechanizeimportcookie...

复制代码 代码如下:

#!/usr/bin/env/ python

#coding=utf-8

import mechanize

import cookielib

# Cookie Jar

cj = cookielib.LWPCookieJar()

# Browser

br = mechanize.Browser()

br.set_cookiejar(cj)

# Browser options

br.set_handle_equiv(True)

br.set_handle_gzip(True)

br.set_handle_redirect(True)

br.set_handle_referer(True)

br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0

br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# Want debugging messages?

#br.set_debug_http(True)

#br.set_debug_redirects(True)

#br.set_debug_responses(True)

# User-Agent (http header)

br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/4.0.0')]

# HTTP access and get response pack

br.open("http://hi.baidu.com/alalmn")

print br.response().read().decode("utf-8")

【python中mechanize库的简单使用示例】相关文章:

Python3 入门教程 简单但比较不错

python迭代器的使用方法实例

python 字符串split的用法分享

python中定义结构体的方法

Python enumerate遍历数组示例应用

Python Web框架Pylons中使用MongoDB的例子

Python的lambda匿名函数的简单介绍

python线程锁(thread)学习示例

python条件和循环的使用方法

python中的一些类型转换函数小结

精品推荐
分类导航