Skip to content

Commit

Permalink
更新答案
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuhang committed Aug 16, 2021
1 parent 0555a12 commit 5276498
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
18 changes: 8 additions & 10 deletions Answers/week1-challenge-04/shiyanlou_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<div align="center">
<h1><img src="https://static.shiyanlou.com/img/louplus/louplus_logo.png"></h1>
<b>实验楼《楼+ 数据分析与挖掘实战》课程仓库|<a href="https://www.shiyanlou.com/louplus/dm">课程报名</a></b>
<b>蓝桥云课《楼+ 数据分析与挖掘实战》课程仓库|<a href="https://www.shiyanlou.com/louplus/dm">课程报名</a></b>
</div>

<br />

### 参考答案
主分支下方包含最新课程的参考答案,历史开班课程的参考答案移步相应分支查看。

### 其他班级

- [随到随学课程挑战参考答案](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)
Expand Down

0 comments on commit 5276498

Please sign in to comment.