当前位置: 首页>>代码示例>>Python>>正文


Python Util.html_soup方法代码示例

本文整理汇总了Python中variety.Util.Util.html_soup方法的典型用法代码示例。如果您正苦于以下问题:Python Util.html_soup方法的具体用法?Python Util.html_soup怎么用?Python Util.html_soup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在variety.Util.Util的用法示例。


在下文中一共展示了Util.html_soup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_for_author

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import html_soup [as 别名]
    def get_for_author(self, author):
        logger.info(lambda: "Fetching quotes from Goodreads for author=%s" % author)

        url = iri2uri(u"https://www.goodreads.com/quotes/search?utf8=\u2713&q=%s" % author)
        soup = Util.html_soup(url)
        page_links = list(Util.safe_map(int,
                                        [pagelink.contents[0] for pagelink in
                                         soup.find_all(href=re.compile('quotes/search.*page='))]))
        if page_links:
            page = random.randint(1, max(page_links))
            url = iri2uri(u"https://www.goodreads.com/quotes/search?utf8=\u2713&q=%s&page=%d" % (author, page))
            soup = Util.html_soup(url)

        return self.get_from_soup(url, soup)
开发者ID:GLolol,项目名称:variety-deb,代码行数:16,代码来源:GoodreadsSource.py

示例2: get_for_keyword

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import html_soup [as 别名]
    def get_for_keyword(self, keyword):
        logger.info(lambda: "Fetching quotes from Goodreads for keyword=%s" % keyword)

        url = iri2uri(u"https://www.goodreads.com/quotes/tag?utf8=\u2713&id=%s" % keyword)
        soup = Util.html_soup(url)
        page_links = list(Util.safe_map(int,
                                        [pagelink.contents[0] for pagelink in
                                         soup.find_all(href=re.compile('quotes/tag.*page='))]))
        if page_links:
            page = random.randint(1, max(page_links))
            url = iri2uri(u"https://www.goodreads.com/quotes/tag?utf8=\u2713&id=%s&page=%d" % (keyword, page))
            soup = Util.html_soup(url)

        return self.get_from_soup(url, soup)
开发者ID:GLolol,项目名称:variety-deb,代码行数:16,代码来源:GoodreadsSource.py

示例3: download_one

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import html_soup [as 别名]
    def download_one(self):
        min_download_interval, min_fill_queue_interval = self.parse_server_options("wallhaven", 0, 0)

        if time.time() - WallhavenDownloader.last_download_time < min_download_interval:
            logger.info(
                lambda: "Minimal interval between Wallhaven downloads is %d, skip this attempt" % min_download_interval
            )
            return None

        logger.info(lambda: "Downloading an image from Wallhaven.cc, " + self.location)
        logger.info(lambda: "Queue size: %d" % len(self.queue))

        if not self.queue:
            if time.time() - self.last_fill_time < min_fill_queue_interval:
                logger.info(
                    lambda: "Wallhaven queue empty, but minimal interval between fill attempts is %d, "
                    "will try again later" % min_fill_queue_interval
                )
                return None

            self.fill_queue()

        if not self.queue:
            logger.info(lambda: "Wallhaven queue still empty after fill request")
            return None

        WallhavenDownloader.last_download_time = time.time()

        wallpaper_url = self.queue.pop()
        logger.info(lambda: "Wallpaper URL: " + wallpaper_url)

        s = Util.html_soup(wallpaper_url)
        src_url = s.find("img", id="wallpaper")["src"]
        logger.info(lambda: "Image src URL: " + src_url)

        extra_metadata = {}
        try:
            extra_metadata["keywords"] = [el.text.strip() for el in s.find_all("a", {"class": "tagname"})]
        except:
            pass

        try:
            purity = s.find("div", "sidebar-content").find("label", "purity").text.lower()
            sfw_rating = {"sfw": 100, "sketchy": 50, "nsfw": 0}[purity]
            extra_metadata["sfwRating"] = sfw_rating

            if self.parent and self.parent.options.safe_mode and sfw_rating < 100:
                logger.info(
                    lambda: "Skipping non-safe download from Wallhaven. "
                    "Is the source %s suitable for Safe mode?" % self.location
                )
                return None
        except:
            pass

        return self.save_locally(wallpaper_url, src_url, extra_metadata=extra_metadata)
开发者ID:GLolol,项目名称:variety-deb,代码行数:58,代码来源:WallhavenDownloader.py

示例4: search

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import html_soup [as 别名]
    def search(self, page=None):
        url = self.url

        if page:
            url = url + ("&" if "?" in self.url else "?") + "page=" + str(page)

        logger.info(lambda: "Performing wallhaven search: url=%s" % url)

        soup = Util.html_soup(url)

        result_count = None
        try:
            result_count = int(soup.find("header", {"class": "listing-header"}).find("h1").text.split()[0])
        except:
            pass

        return soup, result_count
开发者ID:GLolol,项目名称:variety-deb,代码行数:19,代码来源:WallhavenDownloader.py

示例5: fetch

# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import html_soup [as 别名]
 def fetch(url, xml=False):
     return Util.xml_soup(url) if xml else Util.html_soup(url)
开发者ID:GLolol,项目名称:variety-deb,代码行数:4,代码来源:APODDownloader.py


注:本文中的variety.Util.Util.html_soup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。