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


Python PyQuery.parents方法代码示例

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


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

示例1: get_topics

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import parents [as 别名]
def get_topics():
    logging.info('Récupération des sujets')
    if config.debug:
        progress = progressbar.NoProgressBar()
    else:
        progress = progressbar.ProgressBar(widgets=[progressbar.SimpleProgress('/'), ' ', progressbar.Bar("#","[","]"), progressbar.Percentage()], maxval=save.nbtopics)
    progress.start()

    n = len(save.topics)
    
    ids = [i["id"] for i in save.topics]
    
    for forum in [i for i in save.forums if (i["type"] == "f" and i["parsed"] == False)]:
        logging.debug('Récupération : sujets du forum %d', forum["id"])
        subtopics = []
        subids = []
        d = PyQuery(url=config.rooturl + '/' + forum['type'] + str(forum['id']) + '-a', opener=fa_opener)
        result = re.search('function do_pagination_start\(\)[^\}]*start = \(start > \d+\) \? (\d+) : start;[^\}]*start = \(start - 1\) \* (\d+);[^\}]*\}', d.text())

        try:
            pages = int(result.group(1))
            topicsperpages = int(result.group(2))
        except:
            pages = 1
            topicsperpages = 0
            
        for page in range(0,pages):
            if page >= 1:
                d = PyQuery(url=config.rooturl + '/' + forum['type'] + str(forum['id']) + 'p' + str(page*topicsperpages) + '-a', opener=fa_opener)

            for i in d.find('div.topictitle'):
                e = PyQuery(i)
                
                id = int(re.search("/t(\d+)-.*", e("a").attr("href")).group(1))
                if id not in ids and id not in subids:
                    logging.debug('Récupération : sujet %d', id)
                    f = e.parents().eq(-2)
                    locked = u"verrouillé" in f("td img").eq(0).attr("alt")
                    views = int(f("td").eq(5).text())
                    subtopics.append({'id': id, 'type': e("strong").text(), 'parent': forum['newid'], 'title': e("a").text(), 'locked': locked, 'views': views, 'parsed': False})
                    subids.append(id)
                    
                    n += 1
                    progress.update(n)
                else:
                    logging.warning('Le sujet %d a déjà été récupéré.', id)
        save.topics.extend(subtopics)
        ids.extend(subids)
        [i for i in save.forums if i == forum][0]["parsed"] = True
    progress.end()
开发者ID:BossBravo,项目名称:Lalf-Forumactif,代码行数:52,代码来源:forumactif-phpbb.py

示例2: _export_

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import parents [as 别名]
    def _export_(self):
        self.logger.debug("Récupération du forum %s (page %d)", self.forum.oldid, self.page)

        # Download the page
        response = self.session.get("/{}p{}-a".format(self.forum.oldid, self.page))
        document = PyQuery(response.text)

        # Get the topics
        for element in document.find("div.topictitle"):
            e = PyQuery(element)

            topic_id = int(re.search(r"/t(\d+)-.*", clean_url(e("a").attr("href"))).group(1))
            if topic_id not in self.announcements:
                f = e.parents().eq(-2)
                locked = 1 if ("verrouillé" in f("td img").eq(0).attr("alt")) else 0
                views = int(f("td").eq(5).text())
                topic_type = TOPIC_TYPES.get(e("strong").text(), 0)
                title = e("a").text()

                self.add_child(Topic(topic_id, topic_type, title, locked, views))
                if topic_type >= 2:
                    # The topic is an announcement, save its id to avoid exporting it again
                    self.announcements.append(topic_id)
开发者ID:Roromis,项目名称:Lalf-Forumactif,代码行数:25,代码来源:topics.py

示例3: get_topics

# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import parents [as 别名]
def get_topics():
    logging.info("Récupération des sujets")
    if config.debug:
        progress = progressbar.NoProgressBar()
    else:
        progress = progressbar.ProgressBar(
            widgets=[progressbar.SimpleProgress("/"), " ", progressbar.Bar("#", "[", "]"), progressbar.Percentage()],
            maxval=save.nbtopics,
        )
    progress.start()

    n = len(save.topics)

    ids = [i["id"] for i in save.topics]

    for forum in [i for i in save.forums if (i["type"] == "f" and i["parsed"] == False)]:
        logging.debug("Récupération : sujets du forum %d", forum["id"])
        subtopics = []
        subids = []
        d = PyQuery(url=config.rooturl + "/" + forum["type"] + str(forum["id"]) + "-a", opener=fa_opener)
        result = re.search(
            "function do_pagination_start\(\)[^\}]*start = \(start > \d+\) \? (\d+) : start;[^\}]*start = \(start - 1\) \* (\d+);[^\}]*\}",
            d.text(),
        )

        try:
            pages = int(result.group(1))
            topicsperpages = int(result.group(2))
        except:
            pages = 1
            topicsperpages = 0

        for page in range(0, pages):
            if page >= 1:
                d = PyQuery(
                    url=config.rooturl
                    + "/"
                    + forum["type"]
                    + str(forum["id"])
                    + "p"
                    + str(page * topicsperpages)
                    + "-a",
                    opener=fa_opener,
                )

            for i in d.find("div.topictitle"):
                e = PyQuery(i)

                id = int(re.search("/t(\d+)-.*", e("a").attr("href")).group(1))
                if id not in ids and id not in subids:
                    logging.debug("Récupération : sujet %d", id)
                    f = e.parents().eq(-2)
                    locked = u"verrouillé" in f("td img").eq(0).attr("alt")
                    views = int(f("td").eq(5).text())
                    subtopics.append(
                        {
                            "id": id,
                            "type": e("strong").text(),
                            "parent": forum["newid"],
                            "title": e("a").text(),
                            "locked": locked,
                            "views": views,
                            "parsed": False,
                        }
                    )
                    subids.append(id)

                    n += 1
                    progress.update(n)
                else:
                    logging.warning("Le sujet %d a déjà été récupéré.", id)
        save.topics.extend(subtopics)
        ids.extend(subids)
        [i for i in save.forums if i == forum][0]["parsed"] = True
    progress.end()
开发者ID:BossBravo,项目名称:Fichiers,代码行数:77,代码来源:forumactif-phpbb.py


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