@txq0211 根据这位大佬的帖子→https://www.52pojie.cn/thread-1615729-1-1.html 成功让我一个新手爬虫成功,虽然只是简单的爬虫,但是给我带来了成功的快感{:301_997:} ,让我更加积极的去学习Python。(我刚把Python基础学完,不经意间刷到了这篇帖子,所以就勾起我的兴趣)
[Python] 纯文本查看 复制代码# coding:utf-8
import re
import requests
# 爬虫试验
url = 'http://bbs.tianya.cn/post-no04-2817267-1.shtml'
resp = requests.get(url).text
# 这里用的正则表达式的非贪婪匹配 话说非贪婪我没搞懂啥意思
maplists = re.findall('original="(.+?)"', resp)
def start():
i = 0
for pic_url in maplists:
pic = requests.get(pic_url)
i += 1
path = '%d.jpg' % i
with open('C:/Users/Administrator/Desktop/' + path, 'wb') as f:
f.write(pic.content)
print('已经完成输出第%d张图片' % i)
if __name__ == '__main__':
start()
这里有个问题就是有些网站图片检索出来的格式是<img src='https://www.52pojie.cn/地址'>这种又怎么爬取呢? 如果直接匹配src,匹配出来是一个空列表,求解?
如果有违规,请版主删帖,谢谢。