西西软件园多重安全检测下载网站、值得信赖的软件下载站!
西西首页 常用软件 软件下载 安卓软件 游戏下载 安卓游戏 MAC应用 驱动下载 安卓电视
系统工具网络工具媒体工具图形图像聊天工具应用软件编程开发手机软件安卓应用电脑安全字体素材

知乎热评爬虫程序

  • 知乎热评爬虫程序
  • 软件大小:65M
  • 更新时间:2020-05-26 09:15
  • 软件语言:中文
  • 软件厂商:
  • 软件类别:国产软件 / 免费软件 / 源码相关
  • 软件等级:3级
  • 应用平台:WinXP, Win7, win8
  • 官方网站:暂无
好评:50%
坏评:50%

本类精品

装机必备软件

软件介绍

知乎热评爬虫程序,由吾爱大神原创制作分享的一个爬虫程序单exe文件版本,可以免费爬取知乎上的一些热评信息,只需要复制自己的知乎cookie链接即可一键开始爬取,可以按照热度榜来进行爬虫搜索,将评论信息存储到本地进行浏览。本次带来知乎热评爬虫程序资源下载,经常浏览知乎的朋友们可以试试。

知乎热评爬虫程序

知乎热评爬虫程序说明

一键爬取知乎热评信息

支持按搜索榜来进行爬取操作

可下载到本地进行浏览

知乎热评爬虫源码内容

# -*- coding:utf-8 -*-

import requests

from lxml import etree

import pandas as pd

import json

from openpyxl import Workbook

from openpyxl.utils.dataframe import dataframe_to_rows

import datetime

from PySide2.QtWidgets import QApplication, QMessageBox,QFileDialog,QHeaderView,QAbstractItemView,QTableWidgetItem

from PySide2.QtUiTools import QUiLoader

import threading

import os

from PySide2.QtGui import  QIcon

class Download:

    def __init__(self):

        self.ui = QUiLoader().load('知乎.ui')

        self.ui.cookies_button.clicked.connect(self.get_cookies)

        self.ui.catch_button.clicked.connect(self.find_hot)

        self.ui.save_button.clicked.connect(self.save2)

        self.cookies = 0000

        self.df = 0000

        self.ui.hot_list.horizontalHeader().resizeSection(0, 80)

        self.ui.hot_list.horizontalHeader().resizeSection(1, 400)

        # self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        self.ui.hot_list.setEditTriggers(QAbstractItemView.NoEditTriggers)

        self.hot_list = 0000

        #self.ui.hot_list.setEditTriggers(QAbstractItemView.NoEditTriggers)

    def get_cookies(self):

        if len(threading.enumerate()) >= 2:

            QMessageBox.about(self.ui,

                              '警告',

                              '正在下载!!'

                              )

            return

        self.ui.cookies_edit.clear()

        self.ui.cookies_edit.paste()

        self.cookies = self.ui.cookies_edit.toPlainText()

    def find_hot(self):

        if len(threading.enumerate()) >= 2:

            QMessageBox.about(self.ui,

                              '警告',

                              '正在下载!!'

                              )

            return

        if self.cookies == 0000:

            QMessageBox.about(self.ui,

                              '警告',

                              '你还没有粘贴进去cookies!下载个锤子'

                              )

            return

        rows = self.ui.hot_list.rowCount()

        for row in range(rows):

            self.ui.hot_list.removeRow(0)

        url = 'https://www.zhihu.com/hot'

        headers = {

            'user-agent': '''Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36''',

            'cookie': self.cookies

        }

        try:

            response = requests.get(url, headers=headers)

        except:

            self.ui.hot_list.insertRow(0)

            item = QTableWidgetItem('错误!')

            self.ui.hot_list.setItem(0, 0, item)

            item = QTableWidgetItem('cookies可能有误,无误的话就重启软件试试~')

            self.ui.hot_list.setItem(0, 1, item)

            return

        html = response.text

        html = etree.HTML(html)

        url_list = html.xpath('''//div[@class='HotList-list']/section/div[@class="HotItem-content"]/a/@href''')

        title_list = html.xpath('''//div[@class='HotList-list']/section/div[@class="HotItem-content"]/a/@title''')

        hot_nums = html.xpath('''//div[@class='HotList-list']/section/div[@class="HotItem-content"]/div/text()''')

        data = {

            'url': url_list,

            'title': title_list,

            'hot': hot_nums

        }

        df = pd.DataFrame(data)

        try:

            df1 = pd.DataFrame(list(df['url'].str.split('/')))

        except AttributeError:

            self.ui.hot_list.insertRow(0)

            item = QTableWidgetItem('错误!')

            self.ui.hot_list.setItem(0, 0, item)

            item = QTableWidgetItem('你可拉倒吧,cookies明显有误!')

            self.ui.hot_list.setItem(0, 1, item)

            return

        df = df.join(df1[[3, 4]])

        df = df.rename(columns={3: 'isque', 4: 'pid'})

        df = df[df['isque'] == 'question']

        for i in range(len(df)):

            dftemp = df.loc[i]

            row = self.ui.hot_list.rowCount()

            self.ui.hot_list.insertRow(row)

            item = QTableWidgetItem(str(dftemp['hot']))

            self.ui.hot_list.setItem(row, 0, item)

            item = QTableWidgetItem(str(dftemp['title']))

            self.ui.hot_list.setItem(row, 1, item)

        self.df = df

    def save2(self):

        if len(threading.enumerate()) >= 2:

            QMessageBox.about(self.ui,

                              '警告',

                              '正在下载!!'

                              )

            return

        print(type(self.df))

        try:

            if self.df == 0000:

                QMessageBox.about(self.ui,

                                  '警告',

                                  '你还没有获取,保存个锤子',

                                  )

                return

        except ValueError:

            pass

        df = self.df

        filePath = QFileDialog.getExistingDirectory(self.ui, "选择存储路径")

        if filePath == '':

            return

        def get_comments(df,cookies):

            pid = df['pid']

            comm_list = []

            print(f'正在爬pid={pid}')

            for i in range(1, 100, 20):

                print(f'其中第{i}个')

                url = f'https://www.zhihu.com/api/v4/questions/{pid}/answers?include=data%5B%2A%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Cis_sticky%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Ccreated_time%2Cupdated_time%2Creview_info%2Crelevant_info%2Cquestion%2Cexcerpt%2Crelationship.is_authorized%2Cis_author%2Cvoting%2Cis_thanked%2Cis_nothelp%2Cis_labeled%2Cis_recognized%2Cpaid_info%2Cpaid_info_content%3Bdata%5B%2A%5D.mark_infos%5B%2A%5D.url%3Bdata%5B%2A%5D.author.follower_count%2Cbadge%5B%2A%5D.topics&limit=20&offset={i}&platform=desktop&sort_by=default'

                headers = {

                    'user-agent': '''Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36''',

                    'cookie': cookies

                }

                res = requests.get(url, headers=headers)

                res.encoding = 'utf-8'

                html = res.text

                data = json.loads(html)['data']

                if data == []:

                    break

                df2 = pd.DataFrame(data)

                df3 = pd.DataFrame(list(df2['author']))

                df3 = df3[['name', 'url_token', 'user_type', 'headline']]

                df4 = df3.merge(df2[['content', 'voteup_count', 'comment_count']], left_index=True, right_index=True)

                comm_list.append(df4)

            a = comm_list[0]

            for j in comm_list[1:]:

                a = a.append(j, ignore_index=True)

            return a

        def thr(df,ui,cookies):

            hot_list = []

            for i in df.index:

                ui.download_edit.append(f'正在爬第{i + 1}个')

                ui.download_edit.ensureCursorVisible()

                comments = get_comments(df.loc[i],cookies)

                hot_list.append(comments)

                #break

            ui.download_edit.append('终于下载完了,正在保存')

            ui.download_edit.ensureCursorVisible()

            wb = Workbook()

            ws = wb.active

            for row in dataframe_to_rows(df[['url', 'title', 'hot']], index=False, header=True):

                ws.append(row)

            count = 1

            for df0 in hot_list:

                title = f'排行第{count}'

                wb.create_sheet(title=title)

                sheet = wb[title]

                for r in dataframe_to_rows(df0, index=False, header=True):

                    sheet.append(r)

                count += 1

            file_time = str(datetime.datetime.now())[:-7]

            file_time = file_time.replace(":", '-')

            file_name = f"知乎热评{file_time}.xlsx"

            wb.save(filePath + '\\' + file_name)

            # QMessageBox.about(ui,

            #                   '通知',

            #                   '久等了,终于下载完成了'

            #                   )

        t1 = threading.Thread(target=thr,args=[df,self.ui,self.cookies])

        t1.start()

app = QApplication([])

app.setWindowIcon(QIcon('0.png'))

d = Download()

d.ui.show()

app.exec_()

os._exit(0)

相关新闻

知乎近30W人担心的问题,一个人是怎样废掉的?警惕这些情况

对于这个问题,要从两点开始回答,怎样的人才算是废掉?他/她是怎样变成这个样子的?

1.染上了严重的恶习

为什么说染上了严重的恶习就算是废掉了?因为恶习会一点一点侵蚀一个人,导致精神迷幻,严重者导致死亡。

这里所指的恶习就是黄赌毒,这三样是每个人坚决不能碰的东西,虽然在中华上下五千年的历史长河中,这三样恶习从来都没有绝迹过,总是有人想要去尝试一番,这也是他们的可怕之处。

黄赌毒会严重影响一个人的心智,侵蚀价值观,道德底线也会不断地降低,最终的结果就是丧失人生价值,失去人生该有的幸福体验。

2.习惯于被动吸收,一切事物逆来顺受

如果硬是要说一个具体的词来描述,“上进心”会贴切一些,一个人丧失了主动思考的能力,对于所有的信息都习惯于被动吸收,从不主动做某件事情。对于外界,无论好事还是坏事,一切都逆来顺受,如同行尸走肉一般浑浑噩噩的生活。

人和植物的基本区别是思想,就是因为有了思想,人才能在进化的过程中变得越来越优秀。

3.封闭社交,拒绝接受新鲜事物

这就好比一个上世纪早期的人,来到现在这个社会,如果拒绝接受任何新鲜事物,并且封闭自己的社交,那么他很难存活下来。

软件截图

知乎热评爬虫程序
    网易云热评墙
    (12)网易云热评墙关键词
    网易云热评墙,网易热评搜罗,新出炉的网易云看热评软件,可以快速搜索不同歌曲的网易云热评,可以查看热度,可以获取有趣的句子评论,无论是伤感的句子,文艺的句子,或者是欢乐向的句子都能在这里找到,可以发现适合作为空间说说的句子哦~网抑云热评,每天更新各种热评句子,伤感,励志!等等!网抑云热评app,可以显示每首歌的经典评价,本次带来的网抑云热评app采用随机显示模式,适合不知道听啥的朋友们下载使用,没有更多>>

    其他版本下载

    热门评论

    最新评论

    发表评论 查看所有评论(0)

    昵称:
    表情: 高兴 可 汗 我不要 害羞 好 下下下 送花 屎 亲亲
    字数: 0/500 (您的评论需要经过审核才能显示)

    下载帮助下载帮助西西破解版软件均来自互联网, 如有侵犯您的版权, 请与我们联系。

    TOP
    软件下载