5行代码实现Python简易爬虫,抓取亚马逊首页

import requests

headers = {
    'authority': 'www.amazon.com',
    'cache-control': 'max-age=0',
    'rtt': '100',
    'downlink': '7.8',
    'ect': '4g',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
    'sec-fetch-user': '?1',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
    'sec-fetch-site': 'cross-site',
    'sec-fetch-mode': 'navigate',
    'referer': 'https://www.amazon.com/',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cookie': 'session-id=136-1846890-2675233; ubid-main=135-9186825-4739358; aws-priv=eyJ2IjoxLCJldSI6MCwic3QiOjB9; aws-target-static-id=1574328096260-555987; aws-target-data=%7B%22support%22%3A%221%22%7D; lc-main=en_US; s_vnum=2017617388388%26vn%3D2; aws-ubid-main=368-2368523-6774828; aws-session-id=135-4385250-1911763; sess-aws-at-main="dpiimGao6GmWACwx5D01BuPiYpXptZXrM5SGGD6L1fM="; aws-business-metrics-last-visit=1589961329571; s_fid=2F58B4996A2316F2-0B4C6B6523423B61; i18n-prefs=USD; x-wl-uid=1bE+RtlWJokDeV8gzp6KnwZEIYvdnc9EqUv/j5zbkewIWsQVY6xB4y8Y78aHHfQdgcALvAcGlFtNBGQ4jkJsvlr//g31Vfv3n9zrXJSIIIGeQwVtYe1hzrWSOGXJ3KCZAvcDFxXIiQuo=; regStatus=registered; _mkto_trk=id:112-TZM-766&token:_mch-amazon.com-1590742253839-60320; aws-session-id-time=2223357980l; aws-session-token=i52Y3W6OwFg6Cqbc2Pb1IaQWphrw8JAtXy+439cMrHnzL+H0ntL98dIHDT5iBTmF/8HM2x6yOPiZyBvALBicmTgEV3hT9tAAgs4rhdhlJpxUQbrmmD65SLRHsMCHtACZ0rVUNWPG2L8+Kh4BXbWq2sn68XpkUDDF2QovoP/YhzKwxOjiZECWnIf7mayj1uNvKNBvbr4kP1Udl2fwDngVmG0pEJ0/OL+l; __utma=194891197.1403979554.1589960891.1589960891.1592637982.2; __utmz=194891197.1592637982.2.2.utmccn=(referral)|utmcsr=us-east-1.signin.aws.amazon.com|utmcct=/oauth|utmcmd=referral; aws-account-alias=015741542882; aws-target-visitor-id=1574328096262-977650.38_0; aws-userInfo=%7B%22arn%22%3A%22arn%3Aaws%3Aiam%3A%3A015741542882%3Auser%2Fadmin%40amztracker.com%22%2C%22alias%22%3A%22015741542882%22%2C%22username%22%3A%22admin%2540amztracker.com%22%2C%22keybase%22%3A%22%22%2C%22issuer%22%3A%22http%3A%2F%2Fsignin.aws.amazon.com%2Fsignin%22%2C%22signinType%22%3A%22PUBLIC%22%7D; s_vn=1621497365238%26vn%3D24; s_dslv=1595499552869; s_nr=1595499552881-Repeat; x-main=6t8C3W27YeqeNRWEY3X2idQREa3SAV85UcjvcuGcpG2bWTRDA8UZvvSSwyB4IeMV; at-main=Atza|IwEBINv2TQX_ng5LMugpmVYRhgvpzTPtZZwy0vz7C9Mm8KU78FYg4FEhTYANsiWszzwCivXk2JpNvF5Ryg7opOSq2ThURm18cq7V510-x-Dbo5GcPt7macejE-ZA3GxTWGCuRcvLPCmg4FA40zVnfEWd_9zuD69QvDLOxCc0JpYlfQ_4sNXUsoNcgurIPOGzlyeulxaPS0nd84TaYvH3DoOMHe-G; sess-at-main="rahZ0ImAq1qrb+ZGCQeCKuNLHrIOPNskvmLcRYwhdO8="; sst-main=Sst1|PQEiWbRhK36yDCFhadvNoYBvCziTCT8qndUicnSU9ZDsdvx918vIq18IRXpHmWiKZ6VSUpUbPgCcgwSbDPdzVGegRmnbLmy_2nWXfJKYvNZdq18xuJ6D2UlFQXrWa9cH_4XJgRKu5R-4KpSXCCn9TB13ttIIzekiuMIJ6PlXs936b1TPVzmfDBusqcXACrHoSApA62Nc196xjRCyLv8Z2Stzi930Nbx66f_RK4Fg8b9wS-Xqhc1WK533i6lNHKKIRqcV-vyHH2Td89M30FBIBvynpWARa5bo63I6FD4tvK_ivaoMWh5VntLVE55j3yPjBxBZFlhBB4GA1cm7UqGgqR8VrA; session-id-time=2082787201l; skin=noskin; csm-hit=tb:XC9TWVR8WJSKSTZ9HBPT+s-XC9TWVR8WJSKSTZ9HBPT|1596593262092&t:1596593262093&adb:adblk_no; session-token=/SNiCTxUdqg4wCzTStps7AajfmbX8xyeeZVKJ/O9d/3prVMNR0MY5bfpPvZwqc/U4Im16iVy78SWdzzulwt+dvp/KJAjHogt3p0UE/xDoQ4W+URbnwimgQXJ2QxndVVqzDhS07v/IFXi1bsbWtuB49iIVI0Fv+2M66nEC637/ZfvXt5rZmtbh1qURAzLevyzG5jPR6CxTwuxDotfTagsr5DM4Aa6Zy6V5wyRx7BdI6JcezuKHXO2uqmhbqUx9+JsAvOfOf+WI31DFmt4Opm5zg==',
}

response = requests.get('https://www.amazon.com/FOXCESD-Exercise-Tangle-Free-Bearings-Skipping/dp/B088R6R7WR', headers=headers)
html = response.text.encode(response.encoding).decode("utf-8")
print(html)