本文整理汇总了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()
示例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)
示例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()