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

哪种语言做网站好合肥网站外包

哪种语言做网站好,合肥网站外包,怎么样建立自己的视频网站,ps制作网站导航图片工具库 爬虫有两种方案: 第一种方式是使用request模拟请求,并使用bs4解析respond得到数据。第二种是使用selenium和无头浏览器,selenium自动化操作无头浏览器,由无头浏览器实现请求,对得到的数据进行解析。 第一种方…

在这里插入图片描述

工具库

爬虫有两种方案:

  • 第一种方式是使用request模拟请求,并使用bs4解析respond得到数据。
  • 第二种是使用selenium和无头浏览器,selenium自动化操作无头浏览器,由无头浏览器实现请求,对得到的数据进行解析。

第一种方案部署简单,效率高,对于静态页面效果较好,对于动态页面效果较差。【可以理解为直接与服务器对接,申请什么数据完全由你自己来决定】

对于网页来说,可以分为静态网页和动态网页,二者的区别是静态网页是对于你的申请切切实实存在一个html网页文件,将这个文件发给你,你浏览器进行渲染。而动态网页则是存在一个服务器框架,处理你的请求,临时组合成一个html网页发给你,你浏览器进行渲染,你得到的是服务器框架的产物。
在这里插入图片描述

因此网页的数据来源也可以分为:
1、静态网页内的,
2、通过Ajax接口申请的,例如商品的评价数量,加载网页时不随网页一块儿得到,而是额外申请
3、通过JS脚本运行+Ajax接口申请的,例如商品的具体评价,只有你点评论栏,JS脚本才会向服务器申请数据

第二种方案部署稍微麻烦,需要安装无头浏览器,但是爬取效果较好,因为是真实的浏览器申请,selenium是模拟真人进行操作,对于反爬虫效果较好。
本文使用的是第一种,所需的工具库:
Python库:
Beautifulsoup
request
json

方法:

1、登录京东,获取登录cookie
2、搜索,得到搜索链接
3、使用request向搜索链接发送请求,得到respond
4、使用bs4解析respond
5、定位想要的数据所在的tag
6、对于一些动态数据,在浏览器开发者工具的network中找到相应的服务器地址,使用request模拟请求,并使用json解析服务器的respond

代码

import requests, json
from bs4 import BeautifulSoup# 基类,后续可以在此之上扩展
class AbstractWebPage:def __init__(self, cookie, use_cookie=True):if use_cookie:self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ''Chrome/80.0.3987.149 Safari/537.36','cookie': cookie}else:self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ''Chrome/80.0.3987.149 Safari/537.36'}self.sess = requests.session()self.sess.headers.update(self.headers)# 目录类,用来表示搜索结果
class Content(AbstractWebPage):def __init__(self, cookie, keyword, end_page):super(Content, self).__init__(cookie)start_url = 'https://search.jd.com/Search?keyword=' + keyword + '&enc=utf-8&wq=' + keywordself.url_list = [start_url + '&page=' + str(j) for j in range(1, end_page + 1)]self.end_page = end_pagedef print(self):print(self.url_list, sep='\n')def get_item_info(self):item_pages_list = []with open("good_info.txt", 'w', encoding='utf-8') as f:f.write("产品名称" + '\t' + '价格' + '\t' + '销量' + '\t' '店铺' + '\n')f.write("*" * 50 + '\n')for url in self.url_list:res = self.sess.get(url)res.encoding = 'utf-8'res = res.text# 定位搜索结果主体,并获取所有的商品的标签soup = BeautifulSoup(res, 'html.parser').select('#J_goodsList > ul')good_list = soup[0].select('[class=gl-i-wrap]')# 循环获取所有商品信息for temp in good_list:# 获取名称信息name_div = temp.select_one('[class="p-name p-name-type-2"]')good_info = name_div.text.strip() + '\t'# 价格信息price_div = temp.select_one('[class=p-price]')good_info += price_div.text.strip() + '\t'# 评价信息comment_div = temp.select_one('[class=p-commit]').find('strong').find('a')comment_url = comment_div.get('href')good_id = comment_url.replace('//item.jd.com/', '').replace('.html#comment', '')# 评价信息没有在主页面内,而是需要另外发送GET获取,服务器地址如下# 这里面的uuid是唯一标识符,如果运行程序发现报错或者没有得到想要的结果# commit_start_url = f'https://api.m.jd.com/?appid=item-v3&functionId' \#                    '=pc_club_productCommentSummaries&client=pc&clientVersion=1.0.0&t' \#                    f'=1711091114924&referenceIds={good_id}&categoryIds=9987%2C653%2C655' \#                    '&loginType=3&bbtf=&shield=&uuid=181111935.1679801589641754328424.1679801589' \#                    '.1711082862.1711087044.29'commit_start_url = f'https://api.m.jd.com/?appid=item-v3&functionId' \'=pc_club_productCommentSummaries&client=pc&clientVersion=1.0.0&t' \f'=1711091114924&referenceIds={good_id}&categoryIds=9987%2C653%2C655'# 发送请求,得到结果comment_res = self.sess.get(commit_start_url)# 编码方式是GBK国标编码comment_res.encoding = 'gbk'comment_res_json = comment_res.json()# 解析得到评论数量good_info += comment_res_json['CommentsCount'][0]['CommentCountStr'] + '\t'# 店铺信息shop_div = temp.select_one('[class=p-shop]')good_info += shop_div.get_text().strip() + '\t'f.write(good_info + '\n')f.write("*" * 50 + '\n')f.close()return item_pages_listif __name__ == "__main__":# cookie,用于验证登录状态,必须要有cookie,否则京东会提示网络繁忙请重试# 获取方法:使用浏览器登录过后按F12,点击弹出界面中最上方的network选项,name栏里面随便点开一个,拉到最下面就有cookie,复制到cookie.txt中# 注意,不要换行,前后不要有空格,只需要复制cookie的值,不需要复制“cookie:”这几个字符# 上面的看不懂的话,看这个:https://blog.csdn.net/qq_46047971/article/details/121694916# 然后就可以运行程序了cookie_str = ''with open('cookie.txt') as f:cookie_str = f.readline()# 输入cookie,关键词,输入结束页数content_page = Content(cookie_str, '手机', 2)content_page.print()urls = content_page.get_item_info()

文章转载自:
http://dinncosatay.ydfr.cn
http://dinncospinal.ydfr.cn
http://dinncoredescription.ydfr.cn
http://dinncoaylmer.ydfr.cn
http://dinncomarkovian.ydfr.cn
http://dinncojainism.ydfr.cn
http://dinncoblastproof.ydfr.cn
http://dinncosignalman.ydfr.cn
http://dinncounluckily.ydfr.cn
http://dinncocivility.ydfr.cn
http://dinncocurettement.ydfr.cn
http://dinncoeffective.ydfr.cn
http://dinncotemperamentally.ydfr.cn
http://dinncosubventionize.ydfr.cn
http://dinncotraducianism.ydfr.cn
http://dinncoguttural.ydfr.cn
http://dinncoboule.ydfr.cn
http://dinncojackfish.ydfr.cn
http://dinncoreviewable.ydfr.cn
http://dinncohistogram.ydfr.cn
http://dinncoaddenda.ydfr.cn
http://dinncopersiflage.ydfr.cn
http://dinncolute.ydfr.cn
http://dinncochained.ydfr.cn
http://dinncosovietism.ydfr.cn
http://dinncojuridical.ydfr.cn
http://dinncoretrogressive.ydfr.cn
http://dinncoastrocyte.ydfr.cn
http://dinncojargon.ydfr.cn
http://dinncodisfeature.ydfr.cn
http://dinncoonomatopoesis.ydfr.cn
http://dinncocalcitonin.ydfr.cn
http://dinncopatientless.ydfr.cn
http://dinncobluestocking.ydfr.cn
http://dinncobackchat.ydfr.cn
http://dinncoempyreumatic.ydfr.cn
http://dinncoaorist.ydfr.cn
http://dinncodisbranch.ydfr.cn
http://dinncosardonyx.ydfr.cn
http://dinncohumberside.ydfr.cn
http://dinncolymphopoietic.ydfr.cn
http://dinncorecumbently.ydfr.cn
http://dinncoamidohydrolase.ydfr.cn
http://dinncogiovanna.ydfr.cn
http://dinncocrosswise.ydfr.cn
http://dinncocybersex.ydfr.cn
http://dinncocarbonari.ydfr.cn
http://dinncokurus.ydfr.cn
http://dinncopolyopia.ydfr.cn
http://dinncodiminishbb.ydfr.cn
http://dinncomulriple.ydfr.cn
http://dinncotumblebug.ydfr.cn
http://dinncopock.ydfr.cn
http://dinncouncombined.ydfr.cn
http://dinncospinout.ydfr.cn
http://dinncomonist.ydfr.cn
http://dinncoius.ydfr.cn
http://dinncomalingery.ydfr.cn
http://dinncosavoia.ydfr.cn
http://dinncozombi.ydfr.cn
http://dinncoworksheet.ydfr.cn
http://dinncooutburst.ydfr.cn
http://dinncotrichiniasis.ydfr.cn
http://dinncohyla.ydfr.cn
http://dinncomink.ydfr.cn
http://dinncoracemic.ydfr.cn
http://dinncocatridges.ydfr.cn
http://dinncoosiris.ydfr.cn
http://dinncounsteady.ydfr.cn
http://dinncodrainless.ydfr.cn
http://dinncokarroo.ydfr.cn
http://dinncocordon.ydfr.cn
http://dinncomiddleweight.ydfr.cn
http://dinncohatchet.ydfr.cn
http://dinncosliceable.ydfr.cn
http://dinncoraftered.ydfr.cn
http://dinncooverfulfilment.ydfr.cn
http://dinncoconscribe.ydfr.cn
http://dinncopotable.ydfr.cn
http://dinncoseptarium.ydfr.cn
http://dinncolandlubber.ydfr.cn
http://dinncocarsey.ydfr.cn
http://dinncounijugate.ydfr.cn
http://dinncountraceable.ydfr.cn
http://dinncohyperdrive.ydfr.cn
http://dinncosilicule.ydfr.cn
http://dinncoturkmen.ydfr.cn
http://dinncoriksdag.ydfr.cn
http://dinncotepidity.ydfr.cn
http://dinncohandhold.ydfr.cn
http://dinncoalmond.ydfr.cn
http://dinncotelstar.ydfr.cn
http://dinncoalguazil.ydfr.cn
http://dinncoloamy.ydfr.cn
http://dinncoastrolatry.ydfr.cn
http://dinncolunatic.ydfr.cn
http://dinncoderacialize.ydfr.cn
http://dinncooccipital.ydfr.cn
http://dinncomanchurian.ydfr.cn
http://dinncoobligee.ydfr.cn
http://www.dinnco.com/news/158607.html

相关文章:

  • 做的好的ppt下载网站培训网站搭建
  • 学做网站论坛教程下载搜索引擎推广方式
  • 长清做网站银川seo
  • 网站建设设计师的工作内容百度软件市场
  • wordpress调用ajax刷新windows10优化软件
  • 广州建网站定制如何进行网站性能优化?
  • 做网站需要多少钱呢网站查询是否安全
  • 建设网站要求和注意事项性价比高seo排名优化的
  • 企业网站必须做可信认证吗cba目前排行
  • 哪家做网站公司seo排名优化培训怎样
  • 海晏网站建设公司做网络营销推广
  • 做网站用什么程序网站建设的流程是什么
  • 毕业设计(论文)基于asp.net技术的web网站开发与设计北京网站优化企业
  • 做海报素材的网站百度我的订单app
  • 郴州网站建设一键制作网站
  • 最早做淘宝客的网站宁波优化推广选哪家
  • 网站关闭与域名备案淘宝搜索关键词排名查询工具
  • 美国网站人肉收做百度推广关键词越多越好吗
  • 汽修网站怎么做网销怎么做才能做好
  • 东宁网站制作windows7优化大师
  • 宁波网站建设公司排名推广平台有哪些渠道
  • 多个wordpress 合并重庆seo排名技术
  • 重庆聚百思网站开发网络营销的推广方式都有哪些
  • 商城网站开发真实费用石家庄自动seo
  • 定制相册哪个网站好seo排名工具
  • 网站代码优化视频教程营销型网站策划方案
  • 网站建设 找客户口碑营销的步骤
  • 福州网站制作服务怎么做好seo内容优化
  • 网站建设与技术团队最新新闻热点话题
  • 广州手机网站建设哪家好网络营销推广方案模板