Пример #1
0
def main():
    print('欢迎使用微信读书爬虫')
    try:
        books = get_bookshelf()
    except:
        print('请检查您的Cookie设置')
        return
    print('您的书架如下:')
    for b in books:
        print(b.bookId,b.title,b.author)

    while True:
        bid = input('想看哪本书的目录,请输入对应书籍id:')

        for c in get_chapters(int(bid)):
            print('#'*c[0],c[1])

        y =  input('是否需要查看该书的热门划线,y/n?')
        if y.lower() == 'y':
            bb = get_bestbookmarks(bid)
            print(bb)

        y =  input('是否需要查看你的笔记,y/n?')
        if y.lower() == 'y':
            bb = get_bookmarklist(bid)
            print(bb)

        y = input('是否需要查看其他书,y/n?')

        if y.lower() == 'y':
            continue
        else:
            print('bye~')
            break
Пример #2
0
 def download_shelf(self):
     """加载书架时默认已经登录,重新获取cookie"""
     if not self.booklist:
         self.update_cookies()
         self.booklist = wereader.get_bookshelf(self.cookies)
         self.books = itertools.cycle(self.booklist)
     self.init_model()
Пример #3
0
def main():
    print("欢迎使用微信读书爬虫")

    try:
        global books
        books = get_bookshelf(cookies)
    except Exception as e:
        print(e)
        print("获取书架失败,请重新运行client.py 扫码登录")
        return
    print(INFO)

    while FLAG:
        operation = input(">>> ").lower()
        func_map.get(operation, lambda: print("非法的选择"))()
Пример #4
0
def old_main():
    print('欢迎使用微信读书爬虫')
    try:
        books = get_bookshelf()
    except:
        print('请检查您的Cookie设置')
        return
    print('您的书架如下:')
    for b in books:
        print(b.bookId, b.title, b.author)

    while True:
        bid = input('想看哪本书的目录,请输入对应书籍id:')
        current_book = [x for x in books if x.bookId == bid][0]

        for c in get_chapters(int(bid)):
            print('#' * c[0], c[1])

        y = input('是否需要查看该书的热门划线,y/n?')
        if y.lower() == 'y':
            bb = get_bestbookmarks(bid)
            print(bb)

        y = input('是否需要查看你的笔记,y/n?')
        if y.lower() == 'y':
            bb = get_bookmarklist(bid)
            print(bb)

        y = input('是否需要保存你的笔记,y/n?')
        if y.lower() == 'y':
            bb = get_bookmarklist(bid)
            with open(f'{current_book.title}-{current_book.bookId}.txt',
                      'w') as f:
                f.write(bb)

        y = input('是否需要查看其他书,y/n?')

        if y.lower() == 'y':
            continue
        else:
            print('bye~')
            break
Пример #5
0
def main():
    print('欢迎使用微信读书爬虫')

    try:
        global books
        books = get_bookshelf()  # get a list of namedtuple book
    except:
        # print('请检查您的Cookie设置')
        # return
        COOKIE = input("请重新输入 Cookie:")
        with open("cookie", 'w') as f:
            f.write(COOKIE)
        return

    if TEST:
        test()
        return

    print(INFO)

    while FLAG:
        operation = input(">>> ").lower()
        func_map.get(operation, lambda: print("非法的选择"))()
Пример #6
0
def main():
    print('欢迎使用微信读书爬虫')

    try:
        global books
        books = get_bookshelf()  # get a list of namedtuple book
    except:
        # print('请检查您的Cookie设置')
        # return
        # Refresh first
        with open("cookie", 'w') as f:
            pass

        url = 'https://weread.qq.com/#login'
        driver = Chrome()
        driver.get(url)
        cookie = driver.get_cookies()
        while driver.get_cookies() == cookie:
            time.sleep(0.1)

        COOKIE = '; '.join([f"{c['name']}={c['value']}" for c in driver.get_cookies()])
        # COOKIE = input("请重新输入 Cookie:")
        with open("cookie", 'w') as f:
            f.write(COOKIE)
        return
        

    if TEST:
        test()
        return

    print(INFO)

    while FLAG:
        operation = input(">>> ").lower()
        func_map.get(operation, lambda: print("非法的选择"))()
Пример #7
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.actionShow.triggered.connect(self.toggle_mode)
        self.ui.actionSave.triggered.connect(self.save_note)
        self.ui.actionLoadShelf.triggered.connect(self.download_shelf)
        self.ui.actionLoadHot.triggered.connect(self.show_hot_note)
        self.ui.actionLoadNotes.triggered.connect(self.download_notes)
        self.ui.statusBar.hide()
        self.pbar = QProgressBar(self)
        self.pbar.setFixedWidth(500)
        self.ui.statusBar.addWidget(self.pbar)
        icon = QtGui.QIcon()
        icon.addPixmap(
            QtGui.QPixmap(os.path.join(root_path, "static/icon.png")),
            QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.setWindowIcon(icon)

        self.browser = QWebEngineView(self)
        self.browser.setGeometry(
            0,
            self.ui.menubar.height(),
            self.width(),
            self.height() - self.ui.menubar.height(),
        )
        self.ui.actionback.triggered.connect(self.browser.back)
        self.ui.actionforward.triggered.connect(self.browser.forward)
        self.ui.actionShelf.triggered.connect(self.view_shelf)
        self.ui.actionLibrary.triggered.connect(self.view_library)

        # 加载外部的web页面
        self.cache_path = os.path.join(root_path, "cache")
        if not os.path.exists(self.cache_path):
            os.mkdir(self.cache_path)

        # 设置缓存目录
        default_profile = QWebEngineProfile.defaultProfile()
        default_profile.setCachePath(self.cache_path)
        default_profile.setPersistentStoragePath(self.cache_path)

        # 记录上次阅读位置
        self.history_url_file = os.path.join(self.cache_path,"history.txt")
        if not os.path.exists(self.history_url_file):
            url = QUrl("https://weread.qq.com/")
        else:
            with open(self.history_url_file,'r') as f:
                url = QUrl(f.read().strip())

        self.browser.urlChanged.connect(self.update_lastpage) # 每次改变都更新还是退出的时候更新

        self.browser.load(url)
        self.model = QStringListModel(self)
        self.item_model = QStandardItemModel(self)
        self.select_model = QItemSelectionModel(self.item_model)
        self.ui.tableView.setModel(self.item_model)
        self.ui.tableView.setSelectionModel(self.select_model)
        self.ui.tableView.setAlternatingRowColors(True)
        self.ui.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)

        self.is_reading_mode = True
        self.note_dir = os.path.join(root_path, "notes")
        if not os.path.exists(self.note_dir):
            os.mkdir(self.note_dir)

        try:
            self.update_cookies()
            self.booklist = wereader.get_bookshelf(self.cookies)
            self.books = itertools.cycle(self.booklist)
            self.curBook = self.booklist[0]
        except Exception:
            self.curBook = None
            self.booklist = None
Пример #8
0
            headers_p.update(Cookie=cookie_in_file[0])
            # 获取用户user_vid
            for item in cookie_in_file[0].split(';'):
                if item.strip()[:6] == 'wr_vid':
                    USERVID = int(item.strip()[7:])
        else:
            app = QApplication(sys.argv)  # 创建应用
            window = MainWindow()  # 创建主窗口
            window.show()  # 显示窗口
            app.exec_()  # 运行应用,并监听事件
    # 文件不存在时再启用登录界面
    else:
        app = QApplication(sys.argv)  # 创建应用
        window = MainWindow()  # 创建主窗口
        window.show()  # 显示窗口
        app.exec_()  # 运行应用,并监听事件

    # 将书架按{'bookId1':"title1"...}的形式储存在字典中
    bookId_dict = get_bookshelf(userVid=USERVID, list_as_shelf=False)
    print('**********************************************************')
    while True:
        print_books_as_tree(userVid=USERVID)
        # 提示输入书本id,正确输入后进入主函数
        bookId = input('请输入书本ID:\n').strip()
        if bookId in bookId_dict.keys():
            y = main(bookId)
            if y == 0:
                break
            elif y == 1:
                continue