python编写爬虫爬取先知社区文章的标题、标题链接、作者、作者链接、文章分类、发布时间、评论数(O(∩_∩)O哈哈~初级小白,暂时没用正则表达式)
import requests
'''爬取全部'''
'''创建个函数输入先知的页数'''
def paqu_xianzhi(n):
for k in range(1,n+1):
r = requests.get('https://xz.aliyun.com?page={}'.format(k))
response = r.text
#print(response)
table1 = response.find('<table class="table topic-list">')
#print(table1)
table2 = response.find('</table>')
#print(table2)
contents = response[table1:table2]
div = contents.split('<tr><td>')
print('Page{}'.format(k))
with open ('b.txt','a',encoding='UTF-8') as file:
file.write('Page{}'.format(k)+'\n')
#print(div[i]) #1-30 30个标题
for