python mechanize模块的broswer对象怎样让它跳转URL啊?就是会自己带上referer的??
展开全部
#主要是以下部分
br = mechanize.Browser()
br.set_handle_referer()
更为详细,来自stackoverflow:
# Browser
br = mechanize.Browser()
br.set_handle_referer(False) # allow everything to be written to
br.set_handle_robots(False) # no robots
br.set_handle_refresh(True) # can sometimes hang without this
br.set_handle_redirect(True)
br.addheaders = [('User-Agent', 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile myTouch 3G Slide Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'),
('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
('Accept-Language', 'en-gb,en;q=0.5'),
('Accept-Encoding', 'gzip,deflate'),
('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
('Keep-Alive', '115'),
('Connection', 'keep-alive'),
('Cache-Control', 'max-age=0'),
('Referer', 'http://yahoo.com')]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询