从网页中检索重新格式化的 URL

Retrieve reformatted URL from webpage

我正在使用(已弃用,但仍然可用)GoogleNews API 来搜索与我关注的某些股票有关的新闻。 API return 是文章的来源和 GoogleNews link,但我更喜欢来源的直接 link。有没有一种方法可以使用 GoogleNews link 并将 link 检索到直接文章?

作为参考,Google 新闻 API 可能 return:http://news.google.com/./articles/CAIiEB8taITanutbSbv39RsNMyMqGQgEKhAIACoHCAow4uzwCjCF3bsCMIrOrwM?uo=CAUieWh0dHBzOi8vd3d3LmJsb29tYmVyZy5jb20vbmV3cy9hcnRpY2xlcy8yMDIyLTAxLTEwL2NoaW5hLXMtY29uc3VtZXJzLXJpc2stZm9tby1hcy1lbGVjdHJpYy1jYXJzLXBvcHVsYXJpdHktc29hcnMta3k4bHNjczbSAQA&hl=en-US&gl=US&ceid=US%3Aen

但我更愿意:https://www.bloomberg.com/news/articles/2022-01-10/china-s-consumers-risk-fomo-as-electric-cars-popularity-soars-ky8lscs6

如有任何帮助,我们将不胜感激!

提前致谢!

尝试使用 requests 包:

import requests

url = 'http://news.google.com/...'

# Set cookie consentement and DON'T USER User-Agent
cookies = {'CONSENT': 'YES+cb.20210720-07-p0.en+FX+410'}
response = requests.head(url, cookies=cookies, allow_redirects=True)
print(response.history[-1].url)

# Output
https://www.bloomberg.com/news/articles/2022-01-10/china-s-consumers-risk-fomo-as-electric-cars-popularity-soars-ky8lscs6