Python爬虫一
Posted hhh江月
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python爬虫一相关的知识,希望对你有一定的参考价值。
Python爬虫一
import requests
import re
import numpy
"""
baidu.com
"""
url = "https://www.baidu.com/"
headers =
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
res = requests.get(url=url, headers=headers)
# print(res.content.decode())
print(res.headers)
# response headers
print(res.encoding)
# encoding
print(res.url)
# url
print(res.cookies)
# cookie
print(res.request)
# request object
print(res.status_code)
# status
print(res.reason)
# OK
print(res.raw)
"""
output:
PS E:\\1\\Documents\\PyTorch> & C:/Users/1/AppData/Local/Programs/Python/Python38/python.exe e:/1/Documents/PyTorch/爬虫/crawlering_basic/basic01.py
'Bdpagetype': '1', 'Bdqid': '0xdda5a3cc00029c72', 'Cache-Control': 'private', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Content-Type': 'text/html;charset=utf-8', 'Date': 'Sat, 22 Jan 2022 12:50:08 GMT', 'Expires': 'Sat, 22 Jan 2022 12:50:06 GMT', 'P3p': 'CP=" OTI DSP COR IVA OUR IND COM ", CP=" OTI DSP COR IVA OUR IND COM "', 'Server': 'BWS/1.1', 'Set-Cookie': 'BAIDUID=E5EC85CADC16EF8D330516F968D186DC:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com, BIDUPSID=E5EC85CADC16EF8D330516F968D186DC; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com, PSTM=1642855808; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com, BAIDUID=E5EC85CADC16EF8DD71B27FC36E9A130:FG=1; max-age=31536000; expires=Sun, 22-Jan-23 12:50:08 GMT; domain=.baidu.com; path=/; version=1; comment=bd, BDSVRTM=0; path=/, BD_HOME=1; path=/, H_PS_PSSID=35411_35104_31253_35733_35488_35776_34584_35490_35700_34812_35796_35323_26350_35751_35746; path=/; domain=.baidu.com, BAIDUID_BFESS=E5EC85CADC16EF8D330516F968D186DC:FG=1; Path=/; Domain=baidu.com; Expires=Thu, 31 Dec 2037 23:55:55 GMT; Max-Age=2147483647; Secure; SameSite=None', 'Strict-Transport-Security': 'max-age=172800', 'Traceid': '1642855808048997633015971351750108159090', 'X-Frame-Options':
'sameorigin', 'X-Ua-Compatible': 'IE=Edge,chrome=1', 'Transfer-Encoding': 'chunked'
utf-8
https://www.baidu.com/
<RequestsCookieJar[<Cookie BAIDUID=E5EC85CADC16EF8DD71B27FC36E9A130:FG=1 for .baidu.com/>, <Cookie BAIDUID_BFESS=E5EC85CADC16EF8D330516F968D186DC:FG=1 for .baidu.com/>, <Cookie BIDUPSID=E5EC85CADC16EF8D330516F968D186DC for .baidu.com/>, <Cookie H_PS_PSSID=35411_35104_31253_35733_35488_35776_34584_35490_35700_34812_35796_35323_26350_35751_35746 for .baidu.com/>, <Cookie PSTM=1642855808 for .baidu.com/>, <Cookie BDSVRTM=0 for www.baidu.com/>, <Cookie BD_HOME=1 for www.baidu.com/>]>
<PreparedRequest [GET]>
200
OK
<urllib3.response.HTTPResponse object at 0x0000025D7F805730>
PS E:\\1\\Documents\\PyTorch>
"""
以上是关于Python爬虫一的主要内容,如果未能解决你的问题,请参考以下文章