通过urllib.request爬取CSDN原创博客标题方法封装
2021-05-02 02:26
标签:lis pil new list lib 方法 strip 标题 pen 返回结果: 通过urllib.request爬取CSDN原创博客标题方法封装 标签:lis pil new list lib 方法 strip 标题 pen 原文地址:https://www.cnblogs.com/CesareZhang/p/12141797.html通过urllib.request爬取CSDN博客原创博客标题方法封装
pat = ‘原创(.*)‘
import re
import urllib.request
def get_csdn(url, pat, page):
title_list = []
for page1 in range(1, int(page) + 1):
new_url = url + str(page1)
result = urllib.request.urlopen(new_url).read().decode("utf-8")
string = re.compile(pat).findall(result)
for title in string:
j = title_list.append(title.strip()) # str.strip()去空格
return title_list
if __name__ == ‘__main__‘:
url = "https://blog.csdn.net/weixin_42760923/article/list/"
pat = ‘原创(.*)‘
page = 5
print(get_csdn(url, pat, page))
print(len(get_csdn(url, pat, page)))
文章标题:通过urllib.request爬取CSDN原创博客标题方法封装
文章链接:http://soscw.com/index.php/essay/81128.html