可以试试轻量级mechanize库,但不支持JS类的重定向
pip install mechanize
# _*_ coding:utf-8 _*_
import mechanize
br = mechanize.Browser()
br.set_handle_equiv(True) # 设置是否处理HTML http-equiv标头
br.set_handle_redirect(True) # 设置是否处理重定向
br.set_handle_referer(True) # 设置是否向每个请求添加referer头
br.set_handle_robots(False) # 设置是不遵守robots中的规则
br.set_handle_gzip(False) # 处理giz传输编码
br.addheaders = [('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36')]
source_url = ""
response=br.open(source_url)
target_url=response.geturl()
print("source_url=" + source_url)
print("target_url=" + target_url)