Python爬虫示例代码
2023-06-19 11:03
Python
157
0
0
0
标题录入
封面图
以下是一个用Python编写的简单网络爬虫的示例代码: ``` import requests from bs4 import BeautifulSoup def spider(max_pages): page = 1 while page <= max_pages: url = ‘https://example.com/page/‘ + str(page) source_code = requests.get(url) plain_text = source_code.text soup = BeautifulSoup(plain_text) for link in soup.findAll(‘a’, {‘class’: ‘someclass’}): href = ‘https://example.com‘ + link.get(‘href’) title = link.string print(href) print(title) page += 1 spider(3) ```
下一篇:
vscode python print 输出窗口中文乱码
标题录入,一次不能超过6条
如何身心愉悦?
T:0.004062s,M:235.04 KB
返回顶部
留言
留言
评论