Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/icoz/habraparse.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricoz <icoz.vt@gmail.com>2017-02-15 21:35:43 +0300
committerGitHub <noreply@github.com>2017-02-15 21:35:43 +0300
commit4b4f644cf159fd1188c480a17929e11aa54dbc64 (patch)
tree838171bcb122ad7c2d64d3573cc2edd82ccf0dd8
parentb450d5a466e1cc35d77d3b52e95b466450f9f7ca (diff)
parentae17c391586fcfdcd40232bec7937e090ddf4152 (diff)
Merge pull request #14 from kvakanet/master
Исправление для geektimes если в авторе не находился href Добавлена проверка атрибута href и добавлено еще одно правило для поиска автора.
-rw-r--r--habr/topic.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/habr/topic.py b/habr/topic.py
index d83d8e4..e9c3631 100644
--- a/habr/topic.py
+++ b/habr/topic.py
@@ -51,15 +51,13 @@ class TMTopic(object):
raise PostDeleted
self.post['title'] = post_title
tmp = \
+ doc.xpath("//a[@class='post-type__value post-type__value_author']") or \
doc.xpath("//div[@class='author-info__username']//a[@class='author-info__nickname']") or \
doc.xpath("//div[@class='author-info__username']//a[@class='author-info__name']") or \
doc.xpath("//div[@class='author-info__username']//span[@class='author-info__name']")
if len(tmp):
self.post['author'] = tmp[0].text
- if tmp[0].attrib.get('href'):
- self.post['author_url'] = ('https://' + self.domain + tmp[0].attrib['href'] )
- else:
- self.post['author_url'] = "https://{}/users/{}".format(self.domain, self.post['author'])
+ self.post['author_url'] = ('https://' + self.domain + tmp[0].attrib['href'] ) if 'href' in tmp[0].attrib else ''
else:
self.post['author_url']= ''
self.post['author'] = ''
@@ -191,7 +189,7 @@ class TestHabraTopic(TestCase):
t = HabraTopic(231957)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(t.author())
- self.assertEqual(t.author(), 'Яндекс')
+ self.assertEqual(t.author(), '@yaklamm')
pp.pprint(t.title())
self.assertEqual(t.title(), 'Memory management в ядре Linux. Семинар в Яндексе')
pp.pprint(t.post['comments_count'])
@@ -236,7 +234,7 @@ class TestGTTopic(TestCase):
t = GeektimesTopic(243447)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(t.author())
- self.assertEqual(t.author(), 'Soundpal')
+ self.assertEqual(t.author(), '@SOUNDPAL')
pp.pprint(t.title())
self.assertEqual(t.title(), 'На что влияет сопротивление наушников')
pp.pprint(t.post['comments_count'])