以及获取作者和时间
时间: 2023-07-01 11:14:19 浏览: 57
在上面提取标题和链接的代码基础上,可以通过以下代码提取帖子的作者和时间信息:
```python
for article in articles:
title = article.find("font", {"class": "list_title"}).text
link = article.find("a")["href"]
author = article.find("td", {"class": "list_vspace"}).text.strip()
time = article.find("td", {"class": "eng list_vspace"}).text.strip()
print(title, link, author, time)
```
在这里,我们通过查看网页源代码,找到了帖子作者和时间的标签,然后使用find方法提取其内容。需要注意的是,这种方法只适用于该网站的特定页面和标签,如果网站页面结构发生变化,代码可能需要进行相应的调整。
相关问题
以及获取文章内容
在前面提取标题、链接、作者和时间的代码基础上,可以通过访问帖子链接,获取帖子的内容:
```python
for article in articles:
title = article.find("font", {"class": "list_title"}).text
link = article.find("a")["href"]
author = article.find("td", {"class": "list_vspace"}).text.strip()
time = article.find("td", {"class": "eng list_vspace"}).text.strip()
# 访问帖子链接,获取帖子内容
article_response = requests.get(link)
article_content = article_response.content
article_soup = BeautifulSoup(article_content, "html.parser")
content = article_soup.find("td", {"class": "board-contents"}).text.strip()
print(title, link, author, time, content)
```
在这里,我们访问了每个帖子的链接,获取了帖子的详细内容。需要注意的是,有些帖子内容可能包含了HTML标签和特殊字符,需要进行相应的处理。同时,也需要注意网站的反爬虫机制,不要发送过于频繁的请求,以免触发网站的限制机制。
通过git log 获取某个人一段时间内的代码量
您可以通过在`git log`命令中使用`--since`和`--until`参数来获取某个人在一段时间内的代码量。以下是一些命令:
1. 获取某个作者在指定日期范围内的代码量
```
git log --author=<author_name> --since=<start_date> --until=<end_date> --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s",add,subs,loc }' -
```
其中,`<author_name>`是需要统计代码量的作者名字,`<start_date>`和`<end_date>`分别是起始日期和结束日期。例如,如果您想获取某个作者在2021年5月1日到2021年5月31日之间的代码量,您可以这样输入命令:
```
git log --author=<author_name> --since=2021-05-01 --until=2021-05-31 --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s",add,subs,loc }' -
```
2. 获取某个作者在最近n天内的代码量
```
git log --author=<author_name> --since=<n_days_ago> --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s",add,subs,loc }' -
```
其中,`<author_name>`是需要统计代码量的作者名字,`<n_days_ago>`是最近n天的日期(例如,7天前是`7.days.ago`)。例如,如果您想获取某个作者在最近7天内的代码量,您可以这样输入命令:
```
git log --author=<author_name> --since=7.days.ago --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s",add,subs,loc }' -
```
请注意,在使用这些命令之前,请确保您已经克隆了整个Git仓库,并且已经切换到正确的分支。
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)