您的位置:首页 > 游戏 > 手游 > 深圳谷歌seo培训班_建立网站时要采用一定的链接结构_线下推广公司_google官方下载

深圳谷歌seo培训班_建立网站时要采用一定的链接结构_线下推广公司_google官方下载

2025/4/22 19:23:34 来源:https://blog.csdn.net/m0_55297736/article/details/142640903  浏览:    关键词:深圳谷歌seo培训班_建立网站时要采用一定的链接结构_线下推广公司_google官方下载
深圳谷歌seo培训班_建立网站时要采用一定的链接结构_线下推广公司_google官方下载

爬虫入门之爬虫原理以及请求响应

爬虫需要用到的库, 叫requests.

在导入requests库之前, 需要安装它, 打开cmd:
输入pip install 库名

pip install requests

后面出现successful或requirement already就说明已经下载成功了!!!

下载出现的问题:
1.有报错或者是下载慢
修改镜像(从国内的仓库下载)
一、临时修改:
pip install 库名 -i 国内仓库地址
pip install requests -i https://mirrors.aliyun.com/pypi/simple/
二、永久修改
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
pip install requests

导入第三方库

下载好requests第三方库之后, 我们需要导入第三方库

import requests

get请求(获取百度网站的响应):

url = 'http://www.baidu.com'
res = requests.get(url)
# 获取响应输出的时候, 响应数据中有乱码
# 解决办法: 在输出内容之前, 设置响应编码
# 响应对象.encoding = '检查内容中charset的值'
res.encoding = "utf-8"
print(res.text)
# 关闭请求, 不关闭会导致资源浪费
res.close()

控制台输出:

<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com