import  requests

# url='https://www.baidu.com/s?wd=python'
url='https://home.cnblogs.com/u/dddzy/'
# kw={'wd':'python'}
headers={'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
# 'cookie':
# '_ga_7DSFGJNPL4=GS1.1.1689858308.1.1.1689858320.0.0.0; _ga_C2LFP3RFGH=GS1.1.1690027606.4.1.1690027935.0.0.0; .Cnblogs.AspNetCore.Cookies=CfDJ8DuWIYDefEVJtUW7VadsHY84qXnCo_l8ICXPKH_9HpPUUoLg0UexS-B3pggZ6-k4VcmwNfX8hC-_PTMWHEmcUrPrX-Z0HANU7_5m32oSqI9fyOFFXG_YwX2qeFt_iqobAYc2-QqQxBePBESquCkkTJO46Xm9uevpzSx6I_Q22Rq6JteIHuwkHSsQQwHeKRXB8dDs2K93OosWtC60LXuhgtQ_iEzUbmSvswC2IkvZoOgSWN4wEa1vz3JkPtFUKqSsIXDGFoF45PIbnsU176zLDVtMNFbGfLXIIXgr-N37l_caMDQ_jf83hMkcDUazIkS97lZI6DerpDFkThj-9kqJI8fUotjqVAV80bQViMduJa47W0ZUBpm_Y4uusk6xG41ADTKyxPT__bZ_wDdyGXS5npz6dD95YzCExRSW5vBPNNVGx-eisdo5aCnmt4NiH5vdtr9QyNXgfvvv2pn5yBgIyC-LAaMz2Pni1GI_wwkmdhtLMTjAEnyUdrYv9p2BAZb9cy1aVpi-aC1dO200N19-vwtVAJ9nQnJrknAIVDzuaIKkdwzd5UZhQn21_e0dLryXGulVCRoyRY2HTZmZUD9FqXQ; .CNBlogsCookie=DD77AEB0830213B71F3A677E8663D649FCE2668228EC3603F880DAA3C068B9581AF426158741EA3DC7A6AA7E74AF977FBC767B24F7C84CA69CBFC469A7245AB324F462F382A7399E576E99798F3C561C3B3383DD; _ga_3Q0DVSGN10=GS1.1.1690027762.6.1.1690028016.2.0.0; affinity=1690028046.3.308.352483|53e09caa9a86f4478a3056efca83512b; _gid=GA1.2.807364554.1690028045; __gads=ID=4bb592e3bd37fcaa:T=1689858308:RT=1690028818:S=ALNI_MZHDipyId3zfRXm-HxR1EkQm4MFOw; __gpi=UID=00000c22a50a8ca4:T=1689858308:RT=1690028818:S=ALNI_MaFUMjTbLjYEsOQEUnxSQsbf2aaFA; cto_bundle=Z6I1X19xJTJGVVVWV01zazlqVHJnZGxvZkxyREE0R0N3aGdvJTJGV0hLTEl6NjgwcTFLQ3E3blB6eE5ENnJKUSUyRlhvTmttT1FmSmFiN25aU1F0a1VEZGdKMHZ2bEpRdWdiOFBLcmdsRXclMkJhOW1YeWx6aVp1aU42Mnp2cDNpMlVZR3B4WTRSaDdk; cto_bidid=ad6Tvl9ucGJ2OWp1d1cxaHo4MHVBRkpwYVZVSGFQS3E2dTExbjVHQWVacG1VN3VNcHgxaUYweVdtUFFYZERySXp2eGFtUDlaNVBCT1hyOWZQTnFmWXZ6N2QwQSUzRCUzRA; _ga_M95P3TTWJZ=GS1.1.1690027757.1.1.1690028828.0.0.0; _ga=GA1.2.87244384.1640697683; _gat=1; _ga_M4YHF1JL8J=GS1.2.1690028045.1.1.1690028829.0.0.0'
}
#构建字典
temp = '_ga_7DSFGJNPL4=GS1.1.1689858308.1.1.1689858320.0.0.0; _ga_C2LFP3RFGH=GS1.1.1690027606.4.1.1690027935.0.0.0; .Cnblogs.AspNetCore.Cookies=CfDJ8DuWIYDefEVJtUW7VadsHY84qXnCo_l8ICXPKH_9HpPUUoLg0UexS-B3pggZ6-k4VcmwNfX8hC-_PTMWHEmcUrPrX-Z0HANU7_5m32oSqI9fyOFFXG_YwX2qeFt_iqobAYc2-QqQxBePBESquCkkTJO46Xm9uevpzSx6I_Q22Rq6JteIHuwkHSsQQwHeKRXB8dDs2K93OosWtC60LXuhgtQ_iEzUbmSvswC2IkvZoOgSWN4wEa1vz3JkPtFUKqSsIXDGFoF45PIbnsU176zLDVtMNFbGfLXIIXgr-N37l_caMDQ_jf83hMkcDUazIkS97lZI6DerpDFkThj-9kqJI8fUotjqVAV80bQViMduJa47W0ZUBpm_Y4uusk6xG41ADTKyxPT__bZ_wDdyGXS5npz6dD95YzCExRSW5vBPNNVGx-eisdo5aCnmt4NiH5vdtr9QyNXgfvvv2pn5yBgIyC-LAaMz2Pni1GI_wwkmdhtLMTjAEnyUdrYv9p2BAZb9cy1aVpi-aC1dO200N19-vwtVAJ9nQnJrknAIVDzuaIKkdwzd5UZhQn21_e0dLryXGulVCRoyRY2HTZmZUD9FqXQ; .CNBlogsCookie=DD77AEB0830213B71F3A677E8663D649FCE2668228EC3603F880DAA3C068B9581AF426158741EA3DC7A6AA7E74AF977FBC767B24F7C84CA69CBFC469A7245AB324F462F382A7399E576E99798F3C561C3B3383DD; _ga_3Q0DVSGN10=GS1.1.1690027762.6.1.1690028016.2.0.0; affinity=1690028046.3.308.352483|53e09caa9a86f4478a3056efca83512b; _gid=GA1.2.807364554.1690028045; __gads=ID=4bb592e3bd37fcaa:T=1689858308:RT=1690028818:S=ALNI_MZHDipyId3zfRXm-HxR1EkQm4MFOw; __gpi=UID=00000c22a50a8ca4:T=1689858308:RT=1690028818:S=ALNI_MaFUMjTbLjYEsOQEUnxSQsbf2aaFA; cto_bundle=Z6I1X19xJTJGVVVWV01zazlqVHJnZGxvZkxyREE0R0N3aGdvJTJGV0hLTEl6NjgwcTFLQ3E3blB6eE5ENnJKUSUyRlhvTmttT1FmSmFiN25aU1F0a1VEZGdKMHZ2bEpRdWdiOFBLcmdsRXclMkJhOW1YeWx6aVp1aU42Mnp2cDNpMlVZR3B4WTRSaDdk; cto_bidid=ad6Tvl9ucGJ2OWp1d1cxaHo4MHVBRkpwYVZVSGFQS3E2dTExbjVHQWVacG1VN3VNcHgxaUYweVdtUFFYZERySXp2eGFtUDlaNVBCT1hyOWZQTnFmWXZ6N2QwQSUzRCUzRA; _ga_M95P3TTWJZ=GS1.1.1690027757.1.1.1690028828.0.0.0; _ga=GA1.2.87244384.1640697683; _gat=1; _ga_M4YHF1JL8J=GS1.2.1690028045.1.1.1690028829.0.0.0'

#稳妥方案
cookies_list=temp.split('; ')
# print(cookies_list)
# temp1='_ga_7DSFGJNPL4=GS1.1.1689858308.1.1.1689858320.0.0.0'
# print(temp1.split('='))
# temp2=temp1.split('=')
cookies = {}
# print(temp2[0])
# print(temp2[-1])
# print(temp2[1])
for cookie in cookies_list:
cookies[cookie.split('=')[0]] = cookie.split('=')[-1]
print(cookies)
# response=requests.get(url,headers=headers)
response=requests.get(url,headers=headers,cookies=cookies)
with open('baidu6.html','wb') as f:
f.write(response.content)
print(response.url)

# response.encoding='utf8'
# print(response.text)
# print(response.encoding)
#
# print(len(response.content.decode()))
# print(response.content.decode())

# print(response.url)
# print(response.status_code)
# print(response.request.headers)
# print(response.headers)
# print(response.cookies)