浏览器模拟 - 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
mechanize还公开了urllib2 API,默认。
mechanize also exposes the urllib2 API, with cookie handling enabled by default.
这篇关于浏览器模拟 - Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文