Python实现自动提取国家地理每日图片,,用Python urll
Python实现自动提取国家地理每日图片,,用Python urll
用Python urllib2和re模块方法写了个实现自动提取国家地理每日一图的小脚本程序。Python源代码贴在下边,希望和大家多多交流,欢迎有更好的想法的建议的朋友们给我留言。
其它Python图片获取相关文章推荐:用Python 获取图片的Base64编码
Python实现自动提取国家地理每日图片代码如下:
import urllib2import re# get page htmlpage = urllib2.urlopen("http://photography.nationalgeographic.com/ngs_pod_ext/searchPOD.jsp?month=06&day=10&year=2009&page=")txt = page.read()#txt2 = page.read()page.close()# define a regex to get the img srcimgre = '<img alt="(?P<alt>[^"]*)" src="(?P<src>/staticfiles/NGS/Shared/StaticFiles/Photography/Images/POD/.+?-ga.jpg)">'# define a regex to get summarysummaryre = '<div class="summary">\s*<h1 class="podsummary">(?P<podsummary>[^<h>]*)</h1>\s*<p class="credit">(?P<credit>[^</>]*)</p>\s*<div class="description">(?P<desc>.*?)<div style="float:right'# get img alt and source#www.iplaypy.comm2 = re.search(imgre, txt)if m2 is not None: print "get picture alt is '%s', src is 'http://photography.nationalgeographic.com%s'" % \ (m2.group("alt"), m2.group("src"))# get descriptionm3 = re.search(summaryre, txt, re.I|re.M|re.S)if m3 is not None: print "photo desc: summary is '%s', credit by '%s', desciption is '%s'" % \ (m3.group("podsummary"), m3.group("credit"), m3.group("desc"))
编橙之家文章,
相关内容
- Python自动输出文件夹下符合条件的全路径名,,Python自动
- Python urllib2发送即时消息到twitter的实现方法,urllib2tw
- Python 按月增加datetime月份的问题,pythondatetime,今天要为
- Python方法解决Url与Tinyurl地址互换问题,pythontinyurl,Pyt
- Python简易邮件查看器源码示例详解,python查看器,Pytho
- Python将汉字数字转换成阿拉伯数字的方法,python阿拉伯
- Python筛法求质数(素数)的生成器示例,python质数,本篇
- Python实现跨平台获取按键方法源码示例,python源码,本文
- Python计算n*n网格生成树数目的方法,python网格,Python计算
- Python实现HTML颜色和RGB颜色互转的方法,pythonrgb,本文是
评论关闭