【发布时间】:2013-06-12 17:41:22
【问题描述】:
我有时需要解析这样提供的 Beautiful Soup 和请求 URL:
当然,这些 URL 通常会“解析”为规范 URL,例如 http://real-website.com/page.html。如何获取解析/重定向链中的最后一个 URL?
我的代码一般是这样的:
from bs4 import BeautifulSoup
import requests
response = requests.get(url)
soup = bs4.BeautifulSoup(response.text, from_encoding=response.encoding)
canonical_url = response.??? ## This is what I need to know
请注意,我并不是要查询 http://bit.ly/bllsht 来查看它的去向,而是当我使用 Beautiful Soup 已经解析它返回的页面时,也获取规范重定向链中最后一个 URL。
谢谢。
【问题讨论】: