资源简介
给定任意关键词,能够通过新浪微博搜索,爬取相关微博的博主id,微博正文,转发数,评论数,点赞数,发布时间
代码片段和文件信息
from urllib.parse import urlencode
import requests
from pyquery import PyQuery as pq
import os
import re
import xlwt
import pandas as pd
current_Path = os.path.dirname(os.path.abspath(__file__)) + ‘\\‘
base_url = ‘https://s.weibo.com/‘
headers = {
‘Host‘:‘m.weibo.cn‘
‘Refer‘:‘https://weibo.com/zzk1996?is_all=1‘
‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/80.0.3987.87 Safari/537.36 Edg/80.0.361.48‘
}
#搜索
def get_Research(research_Wordspage):
params = {
‘q‘: research_Words
‘Refer‘: ‘index‘
‘page‘: str(page)
}
url = ‘https://s.weibo.com/weibo?‘ + urlencode(params)
#print(url)
# print(urlencode(params))
try:
response = requests.get(url)
if response.status_code == 200:
return response.text
except requests.Connectionerror:
return None
def get_Information(research_Wordspage):
res = []
html = get_Research(research_Wordspage)
doc = pq(html)
#print(doc)
with open(current_Path + ‘test.txt‘‘w+‘encoding = ‘utf8‘) as f:
f.write(html)
# items = doc(“.content“).items()
items = doc(“div[class=‘card‘]“).items()
for li in items:
temp_Info_Dict = {}
###抽取昵称
info = li.find(‘div‘)(‘.name‘)
nick_Name = info.attr(‘nick-name‘)
temp_Info_Dict[‘博主id‘] = nick_Name
###抽取内容
# text = li(‘.txt‘)
text = li(“p[node-type=‘feed_list_content_full‘]>a“)
temp_Info_Dict[‘微博正文‘] = text.text()
if temp_Info_Dict[‘微博正文‘] == ‘‘:
- 上一篇:算法的python实现代码、测试数据集及结果
- 下一篇:bow python实现
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论