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-07-09 14:38:15 +0300
committericoz <icoz.vt@gmail.com>2017-07-09 14:38:15 +0300
commit5aed67eb79e641ad633905066e9cf3d7093dc483 (patch)
treeff064f4754fb6b1f98dcd4e12b0ba3402bc52c08
parentdcc9d0802613c0c08a137977fed43f457dac1a26 (diff)
user.py:
- изменена разметка на Хабрахабре, параметр "дата регистрации"
-rw-r--r--habr/user.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/habr/user.py b/habr/user.py
index 323026e..e3e512c 100644
--- a/habr/user.py
+++ b/habr/user.py
@@ -113,11 +113,14 @@ class TMUser(object):
def _parseUserpage(self):
# print(self._doc)
# check for BAN
- if self._doc.xpath("//div[@class='main']/h1")[0].text.strip() == "Доступ закрыт":
+ val = self._doc.xpath("//div[@class='main']/h1")
+ if val and val[0].text.strip() == "Доступ закрыт":
# maybe raise ERROR???
return
p_tags = self._doc.xpath("//div[@class='user_profile']//ul[@id='people-tags']//a/span")
- date_of_registration = self._doc.xpath("//div[@class='user_profile']//dd[@class='grey']")[0].text.strip()
+ # date_of_registration = self._doc.xpath("//div[@class='user_profile']//dd[@class='grey']")[0].text.strip()
+ tmp = self._doc.xpath("//div[@class='user_profile']//p[@class='profile-section__invited']")
+ date_of_registration = tmp[0].text.strip() if tmp else ""
tmp = self._doc.xpath("//div[@class='user_profile']//dl[last()]/dd")
date_of_last_login = tmp[0].text.strip()
@@ -189,7 +192,8 @@ class TMUser(object):
url = self._genFavoritesUrlByUser(self._username)
doc = html.document_fromstring(requests.get(url).text)
# check for BAN
- if doc.xpath("//div[@class='main']/h1")[0].text.strip() == "Доступ закрыт":
+ val = self._doc.xpath("//div[@class='main']/h1")
+ if val and val[0].text.strip() == "Доступ закрыт":
# maybe raise ERROR???
return
out = dict()