From 52764983b7080c3ca760e38c38c9a71cf0c2ed3e Mon Sep 17 00:00:00 2001 From: huhuhang Date: Mon, 16 Aug 2021 10:17:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Answers/week1-challenge-04/shiyanlou_user.py | 18 ++++++++---------- README.md | 7 ++++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Answers/week1-challenge-04/shiyanlou_user.py b/Answers/week1-challenge-04/shiyanlou_user.py index 99fd8aa..268c640 100644 --- a/Answers/week1-challenge-04/shiyanlou_user.py +++ b/Answers/week1-challenge-04/shiyanlou_user.py @@ -4,18 +4,16 @@ def user_info(user_id): - url = "https://www.shiyanlou.com/users/{}/".format(user_id) + url = "https://www.lanqiao.cn/users/{}/".format(user_id) content = requests.get(url) if content.status_code == 200: tree = html.fromstring(content.text) - user_name = tree.xpath( - '//div[@class="user-meta"]/span/text()')[0].strip() - user_level = tree.xpath( - '//div[@class="user-meta"]/span/text()')[1].strip()[1:] - join_date = tree.xpath( - '//span[@class="user-join-date"]/text()')[0].strip()[:10] - return user_name, int(user_level), join_date + # 首先选取所以 div 元素,要求其 class 属性中包含 name 字段 + # 再取 div 下的 span + user_name = tree.xpath("//div[contains(@class, 'name')]/span/text()")[0].strip() + user_level = tree.xpath("//div[contains(@class, 'name')]/span/text()")[1].strip()[1:] + return user_name, int(user_level) else: - user_name, user_level, join_date = (None, None, None) - return user_name, user_level, join_date + user_name, user_level = (None, None) + return user_name, user_level \ No newline at end of file diff --git a/README.md b/README.md index 31dac9e..37b995d 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@

- 实验楼《楼+ 数据分析与挖掘实战》课程仓库|课程报名 + 蓝桥云课《楼+ 数据分析与挖掘实战》课程仓库|课程报名

-### 参考答案 +主分支下方包含最新课程的参考答案,历史开班课程的参考答案移步相应分支查看。 + +### 其他班级 -- [随到随学课程挑战参考答案](https://github.com/shiyanlou/louplus-dm/tree/v3/Answers) - [第 12-13 期挑战参考答案](https://github.com/shiyanlou/louplus-dm/tree/v3/Answers) - [第 07-11 期挑战参考答案](https://github.com/shiyanlou/louplus-dm/tree/v2/Answers) - [第 01-06 期挑战参考答案](https://github.com/shiyanlou/louplus-dm/tree/master/Answers)