荆门自学编程网课方法有时候,同样一个图链,过一段时间去抓就好了,或者换个网络就好了。我猜测是被反爬,但证据不足,所以只能降低爬取频率,比如每发送接收一次POST请求便10s左右,但还是会有失败的情况,如果大家有更好的意见,欢迎交流。目前情况,正常情况100%爬取完全没问题,异常情况90%以上吧。
#!/usr/bin/env python# -*- coding:utf-8 -*-# date: 2018.03.07"""Capte pictes fm lofter with username."""import reimport osimport platformimport requestsimport timeimport randomdef _get_path(username):
path = { 'Windows': 'D:/litreily/Pictes/python/lofter/' + username, 'Linux': '/mnt/d/litreily/Pictes/python/lofter/' + username
pnt('The blogid of %s is: %s' % (username, blogid)) retn blogid except Exception as e:
timestamp = time_pattern.search(html).gup(1) retn str(timestamp)def _get_imgls(username, blog, headers):
pnt('Blog\t%s\ith %d\tpictes' % (blog_l, len(imgls))) retn imglsdef _capte_images(imgl, path):