python抓网页资源小脚本
2012-11-19 23:24
155 查看
#!/usr/bin/env python # coding: utf-8 import urllib def filter_src(file_name): resource_list = [] f_obj = open(file_name) for f_line in f_obj: if '404' in f_line: str_goal = f_line.strip().split(' ')[7] if not str_goal in resource_list: print str_goal if '/static' in str_goal: str_goal = str_goal.replace('/static', '') resource_list.append(str_goal[:-1]) print resource_list return resource_list def down_src(source_list): base_url = "http://www.ttcrm.com" down_path = r"src" for source in source_list: source_url = base_url + source source_path = down_path + source print source_url source_stram = urllib.urlopen(source_url) f_obj = open(source_path,'wb') f_obj.write(source_stram.read()) if __name__=='__main__': file_name = 'src.txt' source_list = filter_src(file_name) down_src(source_list)
关键点在于保存是以二进制方式保存!
f_obj = open(source_path,'wb') f_obj.write(source_stram.read())
相关文章推荐
- 用Python开发网页自动化测试脚本
- 解决谷歌搜索技术文章时打不开网页问题的python脚本
- 【脚本语言系列】关于Python网页服务Microsoft IIS,你需要知道的事
- Python小脚本 002 批量下载网页链接中的图片
- java 网页版 找出删除你的微信好友(翻译修改自python脚本)
- 用python写了一个读取网页的url的脚本
- 用adb(调试桥)使用python脚本辅助微信小程序跳一跳简单实用教程【新人适用一条龙】附带资源
- 【脚本语言系列】关于Python网页服务Apache,你需要知道的事
- python编写网页爬虫脚本并实现APScheduler调度
- python登录csdn并自动评论下载资源脚本
- 有人这么比较:ASP,JSP,JSP,Python,Ruby,PERL 等网页脚本语言的比较
- Python 3 抓取网页资源的 N 种方法
- Python 3 抓取网页资源的 N 种方法
- python3 抓取网页资源的 N 种方法
- python3 抓取网页资源的 N 种方法
- 资源分享_Django.GitHub Python网页框架Django资源集合
- 一个检测网页是否有日常链接的python脚本
- [Python脚本]——网页爬虫开始
- 【脚本语言系列】关于Python网页服务Plone,你需要知道的事
- python3 抓取网页资源的 N 种方法