Exemplo n.º 1
0
def ruku(source, classification, fiction_name, fiction_img, author,
         viewing_count, fiction_update_time, status, is_vip, chapter_name,
         chapter_content, chapter_update_time):
    '''
    入库
    :return:
    '''
    if not models.Classification.objects.filter(name=classification,
                                                source=source).exists():
        Classification = models.Classification(name=classification,
                                               source=source)
        try:
            Classification.save()
        except Exception:
            Classification = models.Classification.objects.get(
                name=classification, source=source)
    else:
        Classification = models.Classification.objects.get(name=classification,
                                                           source=source)

    if not models.Fiction_list.objects.filter(fiction_name=fiction_name,
                                              author=author):
        Fiction_list = models.Fiction_list(cassificationc=Classification,
                                           fiction_name=fiction_name,
                                           viewing_count=viewing_count,
                                           author=author,
                                           update_time=fiction_update_time,
                                           status=status,
                                           image=fiction_img)
        Fiction_list.save()
    else:
        models.Fiction_list.objects.filter(fiction_name=fiction_name,
                                           author=author).update(
                                               viewing_count=viewing_count,
                                               update_time=fiction_update_time,
                                               status=status,
                                           )
        Fiction_list = models.Fiction_list.objects.get(
            fiction_name=fiction_name, author=author)

    if not models.Fiction_chapter.objects.filter(chapter_name=chapter_name,
                                                 fiction_name=Fiction_list):
        Fiction_chapter = models.Fiction_chapter(
            chapter_name=chapter_name,
            fiction_name=Fiction_list,
            is_vip=is_vip,
            chapter_content=chapter_content,
            update_time=chapter_update_time)
        Fiction_chapter.save()
    else:
        if chapter_content:
            models.Fiction_chapter.objects.filter(
                chapter_name=chapter_name, fiction_name=Fiction_list).update(
                    chapter_name=chapter_name,
                    fiction_name=Fiction_list,
                    is_vip=is_vip,
                    chapter_content=chapter_content,
                    update_time=chapter_update_time)
    print("来源:{} , 分类:{} , 书名:{} , 作者:{} , 章节:{} ".format(
        source, classification, fiction_name, author, chapter_name))
Exemplo n.º 2
0
def ruku(fiction_url):
    '''
    入库
    :param fiction_url:
    :return:
    '''
    chapter_list = get_chapter(fiction_url)
    for v2 in chapter_list['chapter_url']:
        chapter_content = get_chapter_content(v2, chapter_list['author'])
        # print(chapter_content)
        if not models.Classification.objects.filter(
                name=chapter_content.get("cassificationc"),
                source="笔趣阁").exists():
            Classification = models.Classification(
                name=chapter_content.get("cassificationc"), source="笔趣阁")
            try:
                Classification.save()
            except Exception:
                pass
        else:
            Classification = models.Classification.objects.get(
                name=chapter_content.get("cassificationc"))

        if not models.Fiction_list.objects.filter(
                fiction_name=chapter_content.get("fiction_name"),
                author=chapter_content.get("author")):
            Fiction_list = models.Fiction_list(
                cassificationc=Classification,
                fiction_name=chapter_content.get("fiction_name"),
                author=chapter_content.get("author"))
            Fiction_list.save()
        else:
            Fiction_list = models.Fiction_list.objects.get(
                fiction_name=chapter_content.get("fiction_name"),
                author=chapter_content.get("author"))
        if not models.Fiction_chapter.objects.filter(
                chapter_name=chapter_content.get("chapter_name"),
                fiction_name=Fiction_list):
            Fiction_chapter = models.Fiction_chapter(
                chapter_name=chapter_content.get("chapter_name"),
                fiction_name=Fiction_list,
                chapter_content=chapter_content.get("chapter_content"))
            Fiction_chapter.save()
        else:
            if chapter_content:
                models.Fiction_list.objects.filter(
                    fiction_name=chapter_content.get("fiction_name"),
                    author=chapter_content.get("author")).update(
                        chapter_name=chapter_content.get("chapter_name"),
                        fiction_name=Fiction_list,
                        chapter_content=chapter_content.get("chapter_content"))
        print("分类:{} , 书名:{} , 作者:{} , 章节:{} ".format(
            chapter_content.get("cassificationc"),
            chapter_content.get("fiction_name"), chapter_content.get("author"),
            chapter_content.get("chapter_name")))
Exemplo n.º 3
0
    def func(fiction_url):
        for k2, v2 in get_chapter(fiction_url).items():
            chapter_content = get_chapter_content(v2)
            # print(chapter_content)
            if not models.Classification.objects.filter(
                    name=chapter_content.get("cassificationc"),
                    source="inbook").exists():
                Classification = models.Classification(
                    name=chapter_content.get("cassificationc"),
                    source="inbook")
                Classification.save()
            else:
                Classification = models.Classification.objects.get(
                    name=chapter_content.get("cassificationc"))

            if not models.Fiction_list.objects.filter(
                    fiction_name=chapter_content.get("fiction_name"),
                    author=chapter_content.get("author")):
                Fiction_list = models.Fiction_list(
                    cassificationc=Classification,
                    fiction_name=chapter_content.get("fiction_name"),
                    author=chapter_content.get("author"))
                Fiction_list.save()
            else:
                Fiction_list = models.Fiction_list.objects.get(
                    fiction_name=chapter_content.get("fiction_name"),
                    author=chapter_content.get("author"))
            if not models.Fiction_chapter.objects.filter(
                    chapter_name=chapter_content.get("chapter_name"),
                    fiction_name=Fiction_list):
                Fiction_chapter = models.Fiction_chapter(
                    chapter_name=chapter_content.get("chapter_name"),
                    fiction_name=Fiction_list,
                    chapter_content=chapter_content.get("chapter_content"))
                Fiction_chapter.save()
                print("分类:{} , 书名:{} , 作者:{} , 章节:{} ".format(
                    chapter_content.get("cassificationc"),
                    chapter_content.get("fiction_name"),
                    chapter_content.get("author"),
                    chapter_content.get("chapter_name")))
            else:
                if chapter_content:
                    models.Fiction_list.objects.filter(
                        fiction_name=chapter_content.get("fiction_name"),
                        author=chapter_content.get("author")).update(
                            chapter_content.get("cassificationc"),
                            chapter_content.get("fiction_name"),
                            chapter_content.get("author"),
                            chapter_content.get("chapter_name"))
Exemplo n.º 4
0
def main(url):
    driver = webdriver.Chrome("D:\\chromedriver.exe")
    driver.get(url)
    # fiction_img = driver.find_element_by_xpath('''//div[@class="page_container"]/img''').get_attribute("src")
    fiction_img = "https://img30.360buyimg.com/ebookadmin/jfs/t5098/313/1865794756/161412/7eccda48/591512c6Na0e6247c.jpg"
    author = "郝景芳"
    for i in range(10):
        js = '''window.scrollBy(0,{});'''.format(i * 1000)
        driver.execute_script(js)
        time.sleep(1)
    content = driver.find_element_by_xpath('''//div[@id="JD_content"]''').text

    Classification = models.Classification(source="京东", name="其他")
    Classification.save()
    fiction = models.Fiction_list(cassificationc=Classification, fiction_name="北京折叠", author=author, status="完成", image=fiction_img)
    fiction.save()
    chapter = models.Fiction_chapter(fiction_name=fiction, chapter_name="北京折叠", chapter_content=content)
    chapter.save()