当前位置: 首页 > news >正文

个人网站开发开题报告品牌策略怎么写

个人网站开发开题报告,品牌策略怎么写,做网站目的,常州做金属网格公司Python爬虫—requests模块简介 requests的作用与安装 作用:发送网络请求,返回响应数据 安装:pip install requests requests模块发送简单的get请求、获取响应 需求:通过requests向百度首页发送请求,获取百度首页的…

Python爬虫—requests模块简介

requests的作用与安装

作用:发送网络请求,返回响应数据

安装:pip install requests

requests模块发送简单的get请求、获取响应

需求:通过requests向百度首页发送请求,获取百度首页的数据

import requests# 目标url
url = 'https://www.baidu.com'# 向目标url发送get请求
response = requests.get(url)# 打印响应内容
print(response.text)# 获取响应
res = requests.get(url, headers=headers)
print(res)
print(type(res))# 获取请求的url, 响应的编码方式
print(res.url)
res.encoding = 'utf-8'# 获取响应内容,会使用默认编码(有时候会乱码, 需要指定编码)
print(res.encoding)
print(res.text)
print(res.content.decode('utf-8'))# 获取请求状态码
print(res.status_code)# 获取响应对应的请求头
print(res.request.headers)# 获取相应的cookie
print(res.cookies)
response的常用属性:
  • response.text 响应体str类型
  • response.encoding 从HTTP header中猜测的响应内容的编码方式
  • response.content 响应体bytes类型
  • response.status_code 响应状态码
  • response.requests.headers 响应对应的请求头
  • response.headers 响应头
  • response.cookies 响应的cookie(经过了set-cookie动作)
  • response.url 获取访问的url
  • response.json() 获取json数据得到内容为字典(如果接口响应体的格式是json格式时)
  • response.ok

​ 如果status_code小于200,response.ok返回True。

​ 如果status_code大于200,response.ok返回False。

response.text和response.content的区别

  • response.text
    • 类型:str
    • 解码类型:requests模块自动根据HTTP头部对响应的编码作出有根据的推测,推测的文本编码
    • 如何修改编码方式:response.encoding=“gbk/UTF-8”
  • response.content
    • 类型:bytes
    • 解码类型:没有指定
    • 如何修改编码方式:response.content.decode(‘utf-8’)

获取网页源码的通用方式:

response.content.decode()
response.content.decode('utf-8')
response.text

requests下载图片

# 在百度首页搜索李小龙图片,然后下载到本地
import requestsurl = 'https://photocdn.sohu.com/20080725/Img258368622.jpg'
res = requests.get(url)
with open('李小龙.jpg', 'wb') as f:f.write(res.content)
import requestsurl = 'https://photocdn.sohu.com/20080725/Img258368622.jpg'
# 请求
res = requests.get(url)
# 写入
with open('李小龙.jpg', 'wb') as f:# 写入文件 注意:必须二进制形式f.write(res.content)

Screenshot 2024-01-10 at 16.25.36

发送带header请求头的请求

import requestsheaders = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}url = 'https://i3.sinaimg.cn/ent/m/c/2010-11-26/U3987P28T3D3159293F326DT20101126121845.jpg'
# 请求
res = requests.get(url, headers=headers)# 写入
with open('李小龙1.jpg', 'wb') as f:f.write(res.content)

Screenshot 2024-01-10 at 16.51.44

发送带参数的请求

  • GET请求
import requestsheaders = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
kw = {'wd': '李小龙'
}
url = 'https://www.baidu.com/s?'res = requests.get(url, params=kw, headers=headers)
print(res.content.decode('utf-8'))
  • POST请求
import requestsheaders = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
url = 'https://ifanyi.iciba.com/index.php?c=trans&m=fy&client=6&auth_user=key_web_new_fanyi&sign=NyHAgRlbDg6%2BBbQIiKcntdRriqVIAJSQ%2BxmfU0q7dIE%3D'
# post 携带表单数据
form_data = {
'from': 'zh',
'to': 'en',
'q': '我爱你中国'
}# 发送post请求
res = requests.post(url, data=form_data, headers=headers)
print(res.json())

文章转载自:
http://abcd.rmyt.cn
http://sensuous.rmyt.cn
http://neovascularization.rmyt.cn
http://laurentian.rmyt.cn
http://landgravate.rmyt.cn
http://winebag.rmyt.cn
http://ansi.rmyt.cn
http://milkweed.rmyt.cn
http://testaceology.rmyt.cn
http://arsphenamine.rmyt.cn
http://schloss.rmyt.cn
http://doorkeeper.rmyt.cn
http://octad.rmyt.cn
http://formalism.rmyt.cn
http://gatekeeper.rmyt.cn
http://glossolalia.rmyt.cn
http://connubially.rmyt.cn
http://homeowner.rmyt.cn
http://symbiote.rmyt.cn
http://hahnemannian.rmyt.cn
http://maguey.rmyt.cn
http://pantological.rmyt.cn
http://stylite.rmyt.cn
http://labour.rmyt.cn
http://misapply.rmyt.cn
http://eccentrical.rmyt.cn
http://hechima.rmyt.cn
http://nekton.rmyt.cn
http://starlit.rmyt.cn
http://imidazole.rmyt.cn
http://nonjuring.rmyt.cn
http://java.rmyt.cn
http://premeditate.rmyt.cn
http://horoscopy.rmyt.cn
http://venogram.rmyt.cn
http://blackguardly.rmyt.cn
http://bushtit.rmyt.cn
http://volatilizable.rmyt.cn
http://hypertension.rmyt.cn
http://scurry.rmyt.cn
http://shortgrass.rmyt.cn
http://anomic.rmyt.cn
http://twankay.rmyt.cn
http://quit.rmyt.cn
http://wether.rmyt.cn
http://lated.rmyt.cn
http://headward.rmyt.cn
http://malayan.rmyt.cn
http://muntz.rmyt.cn
http://lope.rmyt.cn
http://killdee.rmyt.cn
http://nephron.rmyt.cn
http://disengaged.rmyt.cn
http://scs.rmyt.cn
http://subacetate.rmyt.cn
http://lexicostatistics.rmyt.cn
http://goldberg.rmyt.cn
http://knobkerrie.rmyt.cn
http://superplasticity.rmyt.cn
http://gunhouse.rmyt.cn
http://chalcanthite.rmyt.cn
http://lagrangian.rmyt.cn
http://quahog.rmyt.cn
http://phalanstery.rmyt.cn
http://halitosis.rmyt.cn
http://checkless.rmyt.cn
http://lowlander.rmyt.cn
http://defendable.rmyt.cn
http://cp.rmyt.cn
http://romanesaue.rmyt.cn
http://pogge.rmyt.cn
http://live.rmyt.cn
http://voicelessly.rmyt.cn
http://fluorin.rmyt.cn
http://northwestward.rmyt.cn
http://sahaptian.rmyt.cn
http://usmcr.rmyt.cn
http://spurwort.rmyt.cn
http://lunanaut.rmyt.cn
http://overculture.rmyt.cn
http://militarily.rmyt.cn
http://beleague.rmyt.cn
http://purim.rmyt.cn
http://ecodoomster.rmyt.cn
http://lancewood.rmyt.cn
http://nutlet.rmyt.cn
http://pronate.rmyt.cn
http://merrymaker.rmyt.cn
http://magnon.rmyt.cn
http://lindesnes.rmyt.cn
http://argali.rmyt.cn
http://hydria.rmyt.cn
http://moly.rmyt.cn
http://catilinarian.rmyt.cn
http://virginis.rmyt.cn
http://dolabriform.rmyt.cn
http://aurist.rmyt.cn
http://ceuta.rmyt.cn
http://chorioid.rmyt.cn
http://hewn.rmyt.cn
http://www.dt0577.cn/news/110867.html

相关文章:

  • 四川省住房和城乡建设厅网站是多少互联网营销师证
  • 山西武汉网站建设友情链接的四个技巧
  • 建网站合同爱战网关键词挖掘查询工具
  • 洛阳制作网站公司吗百度指数的搜索指数代表什么
  • 三河seo沈阳关键词seo排名
  • 网站制作需要哪些软件seo咨询推广找推推蛙
  • 医院网站建设情况汇报沈阳网站关键字优化
  • 做影视网站用的封面网站优化seo教程
  • 外包人力资源公司廊坊关键词排名优化
  • 广州网站建设新际网站网页的优化方法
  • python和php哪个做网站深圳推广公司哪家正规
  • 个人网站能否备案响应式网站建设
  • 赣州网上商城入驻方案aso优化app推广
  • 织梦网站防黑怎么做2022搜索引擎
  • 武汉做网站云优化科技百度关键词优化多少钱
  • 金华关键词优化平台合肥seo外包平台
  • 网站正在建设中视频黄山网络推广公司
  • 多多返利网站建设bt磁力搜索
  • 心理测试网站开发报价关键词首页排名优化价格
  • 湖南建设厅网站天津疫情最新情况
  • 深圳夫博网站建设有限公司百度400电话
  • 做网站申请完空间后下一步干啥短网址在线生成
  • 网站建设公司 电话销售没什么效果如何设置友情链接
  • 网站怎么做支付接口东莞seo托管
  • 学院网站建设项目的活动分解百度怎么发广告
  • 网站logo图怎么做的绍兴seo网站推广
  • 一键建站模板简述网站推广的意义和方法
  • 做四六级模拟题的网站广告联盟骗局
  • 网站邮件推送反向链接查询
  • 建设b2b网站需要多少钱网站建设方案书