浏览器模拟 - 的Python [英] Browser simulation - Python
本文介绍了浏览器模拟 - 的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过Python脚本访问几个HTML网页,问题是,我需要COOKIE的功能,因此一个简单的urllib HTTP请求将无法工作。
I need to access a few HTML pages through a Python script, problem is that I need COOKIE functionality, therefore a simple urllib HTTP request won't work.
任何想法?
推荐答案
查看机械化。 在Python编程状态网页浏览。结果
它处理Cookie自动的。
check out Mechanize. "Stateful programmatic web browsing in Python".
It handles cookies automagically.
import mechanize
br = mechanize.Browser()
resp = br.open("http://www.mysitewithcookies.com/")
print resp.info() # headers
print resp.read() # content
机械化也暴露了urllib2的API,以默认启用cookie处理。
mechanize also exposes the urllib2 API, with cookie handling enabled by default.
这篇关于浏览器模拟 - 的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文