从网页中检索重新格式化的 URL
Retrieve reformatted URL from webpage
我正在使用(已弃用,但仍然可用)GoogleNews API 来搜索与我关注的某些股票有关的新闻。 API return 是文章的来源和 GoogleNews link,但我更喜欢来源的直接 link。有没有一种方法可以使用 GoogleNews link 并将 link 检索到直接文章?
如有任何帮助,我们将不胜感激!
提前致谢!
尝试使用 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
我正在使用(已弃用,但仍然可用)GoogleNews API 来搜索与我关注的某些股票有关的新闻。 API return 是文章的来源和 GoogleNews link,但我更喜欢来源的直接 link。有没有一种方法可以使用 GoogleNews link 并将 link 检索到直接文章?
如有任何帮助,我们将不胜感激!
提前致谢!
尝试使用 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