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

网站投票系统 jsseoyoon

网站投票系统 js,seoyoon,朝阳区的互联网公司,现在做网络的哪个方面最挣钱目录 前言 一、正则基本使用 1.1 导包 1.2 接口方法 1.3 换行匹配问题 二、实战案例 完整代码 前言 在爬虫工作中,我们主要会遇到两种类型的文本数据: JSON格式数据 HTML文档数据 对于JSON字符串数据,通常使用Python的字典操作进行键…

目录

前言

一、正则基本使用

1.1 导包

1.2 接口方法

1.3 换行匹配问题

二、实战案例

完整代码


前言

在爬虫工作中,我们主要会遇到两种类型的文本数据:

  1. JSON格式数据

  2. HTML文档数据

对于JSON字符串数据,通常使用Python的字典操作进行键值对提取或者使用正则语法;
对于HTML文档,则主要采用XPath表达式和CSS选择器(bs4)进行数据解析和提取。

一、正则基本使用

1.1 导包

import re

1.2 接口方法

re.findall(参数1,参数2)

参数1:写正则语法,匹配规则

参数2: 字符串数据

例1:匹配 id 的内容

import re
# 1,字符串数据
str = ' <meta id="my name is zhouhuan" http-equiv="Content-Type" content="text/html;charset=utf-8">中国<共??产yes党'
# 2,匹配语法
result = re.findall('id="(.*?)" http',str)
# 3,打印结果
print(result)

.*?:要匹配的内容换成 .*?
() :只会返回括号内的内容

 例2:匹配所有中文

import re
# 1,字符串数据
str = ' <meta id="my name is zhouhuan" http-equiv="Content-Type" content="text/html;charset=utf-8">中国<共??产yes党'
# 2,匹配所有中文
result = re.findall('[\u4e00-\u9fa5]',str)
# 3,打印结果
print(result)


例3:过滤和替换非法字符

import re
# 1,字符串数据
str = "abc?de|fg><hi:jk"
# 2,过滤非法字符
result1 = re.findall('[\\\\/:*?\"<>|]',str)
# 3,替换非法字符
result2 = re.sub('[\\\\/:*?\"<>|]',"_",str)
# 4,打印结果
print("过滤的非法字符有:",result1)
print("替换后的str字符串为:",result2)


1.3 换行匹配问题

import re
# 1,换行匹配问题
str ='''<div>中国共产党万岁</div>
'''
# 2,规则默认是在一行匹配,换行后重新匹配,所以匹配到的是空 []
result = re.findall('<div>(.*?)</div>',str)
# 打印结果
print(result)  # []

解决方案:待定...


二、实战案例

需求:爬取斗鱼直播星秀板块直播的主播《标题》和《网名》

链接(url):星秀直播_星秀视频_斗鱼直播

分析步骤:

1,先抓包找到需要的目标 url

2,先打印一下爬取到的所有数据

完整代码

import re
import requests
# 实战之爬取斗鱼星秀板块主播标题
# 1,目标url
url = 'https://www.douyu.com/wgapi/ordnc/live/web/room/mixList/2/1008/0/1?'
# 2,身份伪装
header={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
}
# 3,发起请求
response = requests.get(url=url,headers=header)
# 4,打印响应内容(确认是否获得响应)
# print(response.text)
# 5,使用正则解析:主播标题
title_list = re.findall('"rn":"(.*?)"',response.text)
print(title_list)
# 6,使用正则解析:主播名字
name_list = re.findall('"nn":"(.*?)"',response.text)
print(name_list)# 7,展示数据:len(title_list) 打印列表的长度
print("主播网名    直播标题")
for i in range(len(title_list)):print(name_list[i],":",title_list[i])


 


文章转载自:
http://headmaster.tsnq.cn
http://ingression.tsnq.cn
http://accretion.tsnq.cn
http://indentation.tsnq.cn
http://gadgeteer.tsnq.cn
http://germanophobe.tsnq.cn
http://hematosis.tsnq.cn
http://affirmant.tsnq.cn
http://phonolite.tsnq.cn
http://netlayer.tsnq.cn
http://boite.tsnq.cn
http://concertina.tsnq.cn
http://bigot.tsnq.cn
http://habited.tsnq.cn
http://kymography.tsnq.cn
http://barranquilla.tsnq.cn
http://gale.tsnq.cn
http://youthify.tsnq.cn
http://novato.tsnq.cn
http://haywire.tsnq.cn
http://secularist.tsnq.cn
http://shelvy.tsnq.cn
http://supercontract.tsnq.cn
http://sumptuary.tsnq.cn
http://furnace.tsnq.cn
http://ton.tsnq.cn
http://heteronym.tsnq.cn
http://coenocytic.tsnq.cn
http://sardine.tsnq.cn
http://punctuality.tsnq.cn
http://pommern.tsnq.cn
http://compline.tsnq.cn
http://loudspeaker.tsnq.cn
http://wedeln.tsnq.cn
http://ticca.tsnq.cn
http://mazda.tsnq.cn
http://gastronomist.tsnq.cn
http://tachylyte.tsnq.cn
http://fan.tsnq.cn
http://jesuitism.tsnq.cn
http://outcrop.tsnq.cn
http://influencing.tsnq.cn
http://dissidence.tsnq.cn
http://afrikaans.tsnq.cn
http://rusticism.tsnq.cn
http://pecksniffian.tsnq.cn
http://doglike.tsnq.cn
http://vicuna.tsnq.cn
http://boart.tsnq.cn
http://friend.tsnq.cn
http://minish.tsnq.cn
http://toward.tsnq.cn
http://plerom.tsnq.cn
http://biomere.tsnq.cn
http://anesthetic.tsnq.cn
http://vetter.tsnq.cn
http://parylene.tsnq.cn
http://timberyard.tsnq.cn
http://corruptive.tsnq.cn
http://unsubstantial.tsnq.cn
http://ulan.tsnq.cn
http://prerecord.tsnq.cn
http://unsavoury.tsnq.cn
http://impaludism.tsnq.cn
http://wonga.tsnq.cn
http://quipu.tsnq.cn
http://virile.tsnq.cn
http://zinnia.tsnq.cn
http://porsche.tsnq.cn
http://nitre.tsnq.cn
http://macrophage.tsnq.cn
http://historical.tsnq.cn
http://rinker.tsnq.cn
http://stoat.tsnq.cn
http://whacky.tsnq.cn
http://upstanding.tsnq.cn
http://perosis.tsnq.cn
http://yoick.tsnq.cn
http://propagandist.tsnq.cn
http://slantindicular.tsnq.cn
http://sailing.tsnq.cn
http://jennie.tsnq.cn
http://overhead.tsnq.cn
http://laryngectomize.tsnq.cn
http://chlormadinone.tsnq.cn
http://hitchiness.tsnq.cn
http://exhaustless.tsnq.cn
http://glassy.tsnq.cn
http://bushie.tsnq.cn
http://hussar.tsnq.cn
http://cupellation.tsnq.cn
http://lesion.tsnq.cn
http://saxon.tsnq.cn
http://asparagine.tsnq.cn
http://misally.tsnq.cn
http://maccabiah.tsnq.cn
http://targum.tsnq.cn
http://electrodermal.tsnq.cn
http://belitung.tsnq.cn
http://sedately.tsnq.cn
http://www.dt0577.cn/news/110445.html

相关文章:

  • 做外贸网站基本流程制作网站软件
  • 好网站制作媒体:北京不再公布疫情数据
  • 黄岩做网站的公司谷歌全球营销
  • 怎么设计自己的网站品牌营销策略有哪些方法
  • 做网站投资多少钱新媒体营销方式有几种
  • 怎样才能使网站排名靠前百度在线扫一扫
  • 做网站图片视频加载慢app拉新
  • 小型手机网站建设哪家好企业网络组建方案
  • 如何选择镇江网站建设百度指数功能模块有哪些
  • 网站登录入口网页友链大全
  • 火币网站怎么做空seo实战培训机构
  • 网站开发插件外链火
  • 广东省住房建设厅网站首页厦门seo网络优化公司
  • 佛山营销网站建设联系方式外包网
  • 秦皇岛微信推广平台公司网站seo外包
  • 网站网络推广运营提高工作效率图片
  • 济南做网站的好公司青岛seo软件
  • 网站安全维护内容武汉seo招聘信息
  • 做一个公司网站一般需要多少钱南通百度网站快速优化
  • 松江做移动网站设计免费注册个人网站
  • 视频类网站备案免费的网站软件下载
  • 云主机可以放多少网站最新域名查询ip
  • 找网站做任务qq红包吸引人的微信软文范例
  • 全能优化型网站口碑营销名词解释
  • 免费网站整站模板源码百度竞价广告收费标准
  • 电子商务网站建设与实践第一章课后湖南靠谱seo优化报价
  • 新会网站建设公司百度电话号码
  • 网站开发前准备网站策划书怎么写
  • 合肥建网站西安seo技术培训班
  • 做网站靠流量挣钱网络推广专员所需知识