海南网站建设网络货运平台有哪些
嗨害大家好鸭,我是小熊猫❤
最近在小破站热门上看见了这个:

不得不说还是挺不一样的
对吧?什么你说不是?
哎呦~ 你干嘛 ~
咳咳…话不多说,让我们一起来康康~
源码、资料电子书点击这里
基本开发环境💨
- Python 3.6
- Pycharm
相关模块的使用💨
- requests
- re
安装Python并添加到环境变量,
pip安装需要的相关模块即可。
一、💥明确需求

二、💥网页数据分析
现在点击历史弹幕数据,同样是有数据加载出来,但是里面的都是乱码了。

请求这个链接还是会得到想要的数据内容。
只需要使用正则表达匹配中文字符就可以匹配出来

三、💥解析数据并多页爬取
弹幕分页是根据日期来的,当点击日期的使用,
返回的给我的数据并不是弹幕数据,而是所有的日期。
那么看到这里有人就会问了,
那我想要爬取目标日期的弹幕数据怎么办?
这两个的url地址是不一样的,
seg.so 才是弹幕数据url地址。
import requests
import redef get_response(html_url):headers = {'cookie': '你自己的cookie','origin': 'https://www.****','referer': 'https://****/video/BV19E41197Kc','user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',}response = requests.get(url=html_url, headers=headers)return responsedef get_date(html_url):response = get_response(html_url)json_data = response.json()date = json_data['data']print(date)return dateif __name__ == '__main__':one_url = 'https://api.****.com/x/v2/dm/history/index?type=1&oid=120004475&month=2021-01'get_date(one_url)
返回的数据是json数据,
根据字典键值对取值就可以得到相关数据。
四、💥保存数据(数据持久化)
def main(html_url):data = get_date(html_url)for date in data:url = f'https://****/x/v2/dm/web/history/seg.so?type=1&oid=120004475&date={date}'html_data = get_response(url).textresult = re.findall(".*?([\u4E00-\u9FA5]+).*?", html_data)for i in result:with open('**弹幕.txt', mode='a', encoding='utf-8') as f:f.write(i)f.write('\n')


五、💥完整代码
import requests
import redef get_response(html_url):headers = {'cookie': '你自己的cookie','origin': 'https://www.bilibili.com','referer': 'https://www.bilibili.com/video/BV19E41197Kc','user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',}response = requests.get(url=html_url, headers=headers)return responsedef get_date(html_url):response = get_response(html_url)json_data = response.json()date = json_data['data']print(date)return datedef save(content):for i in content:with open('B站弹幕.txt', mode='a', encoding='utf-8') as f:f.write(i)f.write('\n')print(i)def main(html_url):data = get_date(html_url)for date in data:url = f'https://api.bilibili.com/x/v2/dm/web/history/seg.so?type=1&oid=120004475&date={date}'html_data = get_response(url).textresult = re.findall(".*?([\u4E00-\u9FA5]+).*?", html_data)save(result)if __name__ == '__main__':one_url = 'https://api.bilibili.com/x/v2/dm/history/index?type=1&oid=120004475&month=2021-01'main(one_url)
今天的文章就是这样啦
我是小熊猫,咱下篇文章再见啦❤

