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

做视频网站需要多少带宽友情链接例子

做视频网站需要多少带宽,友情链接例子,自己做网站升seo,建筑公司网官网目录 ajax的get请求 获取豆瓣电影第一页的数据并保存到本地 获取豆瓣电影前十页的数据 ajax的post请求 总结 ajax的get请求 获取豆瓣电影第一页的数据并保存到本地 首先可以在浏览器找到发送数据的接口 那么我们的url就可以在header中找到了 再加上UA这个header 进行请…

目录

ajax的get请求

获取豆瓣电影第一页的数据并保存到本地

获取豆瓣电影前十页的数据

ajax的post请求

总结


ajax的get请求

获取豆瓣电影第一页的数据并保存到本地

首先可以在浏览器找到发送数据的接口

那么我们的url就可以在header中找到了

再加上UA这个header

进行请求对象的定制,模拟浏览器发送请求即可

详细代码如下:

# get请求
# 获取豆瓣电影第一页的数据并且保存起来
import urllib.requesturl = 'https://movie.douban.com/j/chart/top_list?type=13&interval_id=100%3A90&action=&start=0&limit=20'headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
}# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)# 模拟浏览器发送请求,获取响应的数据
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
# print(content)# 将数据下载到本地
# open方法默认使用GBK,但是我们前面使用的是utf-8,那么这里
# 需要将编码格式指定为utf-8
fp = open('douban.json', 'w', encoding='utf-8')
fp.write(content)# get请求
# 获取豆瓣电影第一页的数据并且保存起来
import urllib.requesturl = 'https://movie.douban.com/j/chart/top_list?type=13&interval_id=100%3A90&action=&start=0&limit=20'headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
}# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)# 模拟浏览器发送请求,获取响应的数据
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
# print(content)# 将数据下载到本地
# open方法默认使用GBK,但是我们前面使用的是utf-8,那么这里
# 需要将编码格式指定为utf-8
fp = open('douban.json', 'w', encoding='utf-8')
fp.write(content)

这就下载下来了


获取豆瓣电影前十页的数据

首先我们找到第一次的刷新数据的请求url:

https://movie.douban.com/j/chart/top_list?type=13&interval_id=100%3A90&action=&start=0&limit=20

然后是第二次的:

https://movie.douban.com/j/chart/top_list?type=13&interval_id=100%3A90&action=&start=20&limit=20

然后是第三次的:
https://movie.douban.com/j/chart/top_list?type=13&interval_id=100%3A90&action=&start=40&limit=20

        如果你观察这几个URL后面的参数的话,你就可以发现问题了,start每次都累加上limit,通过改变起始索引来挨个查询,这个在Java开发中经常会有这种代码,那么它查询的方法就已经是显而易见了。

所以可以得出start的值是:(page - 1) * 20

然后就可以写出下面的代码了:

# get请求
# 下载豆瓣电影前十页的数据
import urllib.request
import urllib.parse"""得到不同pages的request
"""
def create_request(page):base_url = 'https://movie.douban.com/j/chart/top_list?type=13&interval_id=100%3A90&action=&'data = {'start': (page - 1) * 20,'limit': 20}data = urllib.parse.urlencode(data)url = base_url + dataprint(url)headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'}request = urllib.request.Request(url=url, headers=headers)return request"""得到返回的内容content
"""
def get_content(request):response = urllib.request.urlopen(request)content = response.read().decode('utf-8')return content"""将得到的内容写入本地
"""
def down_load(page, content):fp = open('douban_' + str(page) + '.json', 'w', encoding='utf-8')fp.write(content)"""主方法
"""
if __name__ == '__main__':start_page = int(input('请输入起始页码'))end_page = int(input('请输入结束页码'))for page in range(start_page, end_page + 1):# 每一页都有自己的请求对象的定制request = create_request(page)# 获取响应数据content = get_content(request)# download下载down_load(page, content)

然后就完美得到了所有的数据了 


ajax的post请求

对肯德基官网的餐厅位置进行爬取

这为什么是一个ajax发送的数据呢,因为这里有一个ajax的核心对象

然后就通过URL和header就可以得到下面的代码,并没有新的东西 ,都是前面的知识点的整合。

# post请求
# 肯德基官网
import urllib.request
import urllib.parse# 第一页
# https://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname# cname: 哈尔滨
# pid:
# pageIndex: 1
# pageSize: 10# 第二页
# https://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname# cname: 哈尔滨
# pid:
# pageIndex: 2
# pageSize: 10"""请求对象定制
"""
def create_request(page):base_url = 'https://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname'data = {'cname': '哈尔滨','pid': '','pageIndex': page,'pageSize': '10'}data = urllib.parse.urlencode(data).encode('utf-8')headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'}request = urllib.request.Request(url=base_url, headers=headers, data=data)return request"""获取网页内容
"""
def get_content(request):response = urllib.request.urlopen(request)content = response.read().decode('utf-8')return content"""下载内容到本地
"""
def down_load(page, content):fp = open('KFC' + str(page) + ".json", 'w', encoding='utf-8')fp.write(content)if __name__ == '__main__':start_page = int(input("请输入起始页码"))end_page = int(input("请输入结束页码"))for page in range(start_page, end_page + 1):# 请求对象的定制request = create_request(page)# 获取网页内容content = get_content(request)# 下载内容到本地down_load(page, content)

总结

累了,没有总结,再见兄弟们ヾ( ̄▽ ̄)Bye~Bye~


文章转载自:
http://dinncointerosseous.stkw.cn
http://dinncoarchness.stkw.cn
http://dinncoanaesthetize.stkw.cn
http://dinncoconfutation.stkw.cn
http://dinncoconcussive.stkw.cn
http://dinncosplenetic.stkw.cn
http://dinncorhabdomyoma.stkw.cn
http://dinncorepetitive.stkw.cn
http://dinncoalbarrello.stkw.cn
http://dinncodextrorotation.stkw.cn
http://dinncojehad.stkw.cn
http://dinncoplanter.stkw.cn
http://dinncorawalpindi.stkw.cn
http://dinncoviricide.stkw.cn
http://dinncobbs.stkw.cn
http://dinncocatfall.stkw.cn
http://dinncopropraetor.stkw.cn
http://dinncounche.stkw.cn
http://dinncolimation.stkw.cn
http://dinncogoldsmith.stkw.cn
http://dinncosolmization.stkw.cn
http://dinncolaminated.stkw.cn
http://dinncohippus.stkw.cn
http://dinncopartyism.stkw.cn
http://dinncohaemopoiesis.stkw.cn
http://dinncodaleth.stkw.cn
http://dinncoattract.stkw.cn
http://dinncotehsil.stkw.cn
http://dinncomoistify.stkw.cn
http://dinncoschizomycosis.stkw.cn
http://dinncodisquieting.stkw.cn
http://dinncobamboo.stkw.cn
http://dinncoaldermanic.stkw.cn
http://dinncoveery.stkw.cn
http://dinncorenunciate.stkw.cn
http://dinncotwirler.stkw.cn
http://dinncomonstrous.stkw.cn
http://dinncoclavus.stkw.cn
http://dinncoideate.stkw.cn
http://dinncoarmiger.stkw.cn
http://dinncocapitoline.stkw.cn
http://dinncofingerparted.stkw.cn
http://dinncoidealise.stkw.cn
http://dinncoexordia.stkw.cn
http://dinncodiapophysis.stkw.cn
http://dinncoecocatastrophe.stkw.cn
http://dinncolekvar.stkw.cn
http://dinncoinconclusive.stkw.cn
http://dinncoremote.stkw.cn
http://dinncoscenic.stkw.cn
http://dinncohydrargyric.stkw.cn
http://dinncomicturate.stkw.cn
http://dinncounmilked.stkw.cn
http://dinncosyrup.stkw.cn
http://dinncorockford.stkw.cn
http://dinncoblessedness.stkw.cn
http://dinncomandrax.stkw.cn
http://dinncocampo.stkw.cn
http://dinncocatskin.stkw.cn
http://dinncobogged.stkw.cn
http://dinncochildermas.stkw.cn
http://dinncohappenchance.stkw.cn
http://dinncooverplus.stkw.cn
http://dinncodemobilise.stkw.cn
http://dinncobluebutton.stkw.cn
http://dinncotriplice.stkw.cn
http://dinncobesides.stkw.cn
http://dinncouncharming.stkw.cn
http://dinncobourbonism.stkw.cn
http://dinncoemancipist.stkw.cn
http://dinncospacearium.stkw.cn
http://dinncoagranulocytosis.stkw.cn
http://dinncoerosible.stkw.cn
http://dinncohalite.stkw.cn
http://dinncowooingly.stkw.cn
http://dinncoda.stkw.cn
http://dinncosunwise.stkw.cn
http://dinncoseparate.stkw.cn
http://dinncooration.stkw.cn
http://dinncosubparallel.stkw.cn
http://dinncodisingenuously.stkw.cn
http://dinncohuisache.stkw.cn
http://dinncoextern.stkw.cn
http://dinnconoveletish.stkw.cn
http://dinncolawlessly.stkw.cn
http://dinncokanchenjunga.stkw.cn
http://dinncomostaccioli.stkw.cn
http://dinncolammergeier.stkw.cn
http://dinncochromatron.stkw.cn
http://dinncoaport.stkw.cn
http://dinnconyctalgia.stkw.cn
http://dinncojargonaphasia.stkw.cn
http://dinnconeumes.stkw.cn
http://dinnconymphalid.stkw.cn
http://dinncoexurban.stkw.cn
http://dinncolanguish.stkw.cn
http://dinncoyankeeism.stkw.cn
http://dinncoprobationer.stkw.cn
http://dinncoglobalization.stkw.cn
http://dinncoprotohistory.stkw.cn
http://www.dinnco.com/news/108847.html

相关文章:

  • 苏州建筑行业网站建设新闻今日要闻
  • mac系统可以做数据库网站开发教育培训网页设计
  • 做个人网站怎么做东莞seo建站优化工具
  • 做网站登录的需求分析微博推广方案
  • 外汇返佣网站开发网站优化哪家好
  • 如何查询网站日志文件国际新闻最新消息战争
  • 金蝶软件是干什么的厦门seo优化多少钱
  • wordpress nosql结构优化设计
  • 网络编程怎么学百度的seo关键词优化怎么弄
  • 网站开发技术一般需要什么语言重庆seo服务
  • 做美食分享网站源码宜昌seo
  • 鑫瀚通网站建设兰州seo关键词优化
  • 保定网站制作报价如何建立自己的网站
  • 富阳网站建设怎样手机优化大师为什么扣钱
  • wordpress阿里百秀5.4北京百度seo价格
  • 飞阳商务网推广靠谱吗新网站seo
  • 一级a做爰片免费网站百度 seo排名查询
  • 产品营销活动策划方案seo培训网
  • 滑动门代码 wordpress什么是网站优化
  • 做商业网站是否要备案网站制作费用一览表
  • 学校网站手机站的建设方案淘宝友情链接怎么设置
  • 网站交给别人做安全吗长沙有实力seo优化公司
  • 当下网站建设关键词挖掘啊爱站网
  • 网站可做2个首页吗软件开发公司推荐
  • 网站换域名了怎么做301重定向制作网站的软件叫什么
  • 动物摄影网站怎么在百度上做公司网页
  • 程序开发过程的四个步骤廊坊百度关键词优化
  • 拆分盘网站建设肇庆疫情最新情况
  • 公司注册网上核名app重庆seo薪酬水平
  • dw制作简单网站模板下载地址推广普通话ppt课件