logo
Loading...

如何使用request觀察所需要的headers? header與解答相同,但是結果卻顯示頁面不存在? - Cupoy

1. 請問要request觀察出我所需要的headers?2. 我的header和d18解答相同,但...

pycrawler-2-d18

如何使用request觀察所需要的headers? header與解答相同,但是結果卻顯示頁面不存在?

2020/04/21 03:26 下午
Python網路爬蟲討論版
DING
觀看數:3
回答數:6
收藏數:1
pycrawler-2-d18

1. 請問要request觀察出我所需要的headers?

2. 我的header和d18解答相同,但是結果卻顯示頁面不存在

import requests
url = 'http://aicoin.cn/'

headers = {
#'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
#'Accept-Encoding': 'gzip, deflate, br'
#'Accept-Language':' zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7'
#'Cache-Control': 'max-age=0'
#'Connection': 'keep-alive'
#'Cookie': 'HWWAFSESID=3628976d521b0d5394; HWWAFSESTIME=1587439298046; _pk_testcookie..undefined=1; _pk_testcookie.2.57ea=1; _ga=GA1.2.243709566.1587439305; _gid=GA1.2.706800466.1587439305; Hm_lvt_3c606e4c5bc6e9ff490f59ae4106beb4=1587439306; _pk_id.2.57ea=3a4b5be0db4c7057.1587439304.3.1587450988.1587450986.; _pk_ses.2.57ea=1; Hm_lpvt_3c606e4c5bc6e9ff490f59ae4106beb4=1587450988; aicoin_session=eyJpdiI6Ildsb0k2d2hWTCtPb1NXQmZpZElnMHc9PSIsInZhbHVlIjoiVVByR29NOUh5Q1Z0NERXWGptOWFmdDd2QmVZTTg0Zk9VMDZEUEV5RnFmYTc0dWQxN1VYRVJESXFPbEFWazY1c0xBWVdlS3B0MTVEZnlIVVUyT0JhYVE9PSIsIm1hYyI6ImVlYmM4MTI1MTczZDU5NDNlZTk2NmNhMGQ2NzA1NTc1NzNmMWRjMzhmMGRiMDA0ZWQ4NjliMmE1MGMxN2Y2MGQifQ%3D%3D'
#'Host': 'www.aicoin.cn'
#'If-None-Match': 'W/"159dfe-gZfwM6JqG42FoDW412bbLlkKQAI"'
#'Sec-Fetch-Dest': 'document'
#'Sec-Fetch-Mode': 'navigate'
#'Sec-Fetch-Site': 'none'
#'Sec-Fetch-User': '?1'
#'Upgrade-Insecure-Requests': '1'
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
}

= requests.get(url, headers=headers)
print(r.text[0:600])
<!DOCTYPE html><html><head><meta charSet="utf-8" class="next-head"/><meta name="viewport" content="width=device-width, initial-scale=1.0" class="jsx-1554617145 next-head"/><meta name="robots" content="noindex" class="jsx-1554617145 next-head"/><title class="jsx-1554617145 next-head">404: 页面不存在 | AICoin</title><link rel="preload" href="https://assets-www.aicoin.net.cn/beta-v20/_next/static/6hleXWGgG2fXN8NUZ9Ide/pages/_app.js" as="script"/><link rel="preload" href="https://assets-www.aicoin.net.cn/beta-v20/_next/static/6hleXWGgG2fXN8NUZ9Ide/pages/_error.js" as="script"/><link rel="preload" href=