获取百度的搜索结果的真实地址

百度搜索的结果都是经过百度加密后的,百度转发的接口,如:

https://www.baidu.com/link?url=OFSePiUaUzt-d1-kvP1krU2_5R3aKLA6otU2dyxBsnQly9jKiOeBRPNvQwiqu8RpfUnikb_H0QPTxDTxjUuJFq&wd=&eqid=eb0976a0000a7edd000000046066a7e8

这里使用python代码获取真实地址

import requests
from urllib import parse

def get_baidu_true_url(link):
parsed = parse.urlsplit(link)
query_dict = parse.parse_qs(parsed.query)
pared_url = f"{parsed.scheme}://{parsed.netloc}/link?url={query_dict['url'][0]}"
return requests.head(pared_url, allow_redirects=True, timeout=10).url


origin_url = "https://www.baidu.com/link?url=qp6atoWSri_evr-3pXTNtukV8ynHxUEcPP9pLrKXY_FTDhN3mo9tnRDmVLaViI8dHrL90S9fTypnoJJXyWyDutWquVvbb7Yi4pTFeqd-9CW&wd=&eqid=9492278500108bd8000000046066a6ac"

get_baidu_true_url(origin_url)
# 'https://blog.yueyawochong.cn/tags/%E7%B3%BB%E7%BB%9F/'