自己写的一个爬蚂蜂窝的景点数据的Python程序,Mark一下
来源:互联网 发布:cf聊天软件下载 编辑:程序博客网 时间:2024/04/30 12:09
#!/usr/bin python#coding:utf-8import sysreload(sys)sys.setdefaultencoding("utf-8")import requestsimport reimport tracebackdef print_fun(entity): for k in entity: print "%s\t%s"%(k,entity[k]) print '-'*70def filter_sum_fun(summary): summary_list=summary.split('\n') summary_list=filter(lambda x:len(x)>10,summary_list) new_summary='\n'.join(summary_list) return new_summaryp_each=re.compile('<div class="ct-text ">(.*?)</div>',re.S)p_link=re.compile('<a href="(.*?)"',re.S)p_name=re.compile('<h3>(.*?)</h3>',re.S)p_region=re.compile('<ul class="seg-info-list clearfix">(.*?)</ul>',re.S)p_final=re.compile('>(.*?)<',re.S)p_summary1=re.compile('summary">(.*?)</div>',re.S)p_summary2=re.compile(u'简介</h3>.*?<p>(.*?)</p>',re.S)p_pic_outer1=re.compile('class="pic-big">(.*?)</div>',re.S)p_pic_outer2=re.compile('class="pic-r">(.*?)</div>',re.S)p_pic_in=re.compile('<img src="(.*?)"',re.S)def get_entity_by_name(tourist_name): url=u'http://www.mafengwo.cn/search/s.php?q=%s&t=poi&seid=A271F36A-F900-49D3-86E1-168806400065'%tourist_name entityList=[] try: html,cont='',[] html=requests.get(url) htmlText=html.text.encode(html.encoding).decode('utf8') cont=p_each.findall(htmlText) for i in cont: entity={} link=p_link.search(i).group(1) if 'sr-keyword' not in p_name.search(i).group(1): continue name_area=p_name.search(i).group(1).replace('<span class="sr-keyword">','').replace('</span>','') region_area=p_region.search(i).group(1).replace('<li>','') naType=p_final.search(name_area).group(1).replace(' - ','-') typer,name=naType.split('-') if ' ' in name: name,alias=name.split(' ',1) else: alias="" region=p_final.search(region_area).group(1).replace(' ','') sub_html=requests.get(link) sub_htmlText=sub_html.text.encode(sub_html.encoding).decode('utf8') summary_area,pic_area=None,None if typer=='景点': summary_area=p_summary1.search(sub_htmlText) pic_area=p_pic_outer1.search(sub_htmlText) elif typer=='娱乐': summary_area=p_summary2.search(sub_htmlText) pic_area=p_pic_outer2.search(sub_htmlText) else: continue summary=summary_area.group(1).replace(' ','').replace('<br/>','').strip() if summary_area else '' pic=p_pic_in.search(pic_area.group(1)).group(1) if pic_area else '' entity['name']=name entity['alias']=alias entity['type']=typer entity['region']=region entity['link']=link entity['summary']=filter_sum_fun(summary) entity['pic']=pic entityList.append(entity) # print_fun(entity) except Exception,e: # sys.stderr.write('=>'+url+'\n') traceback.print_exc() #output the result return entityListif __name__ == "__main__": name=raw_input('please enter the tourist_name:') res_list=get_entity_by_name(name) for i in res_list: print_fun(i)
阅读全文
0 0
- 自己写的一个爬蚂蜂窝的景点数据的Python程序,Mark一下
- python爬取携程和蚂蜂窝的景点评论数据\python爬取携程评论数据\python旅游网站评论数据爬虫
- mark一下,今天开始写自己的博客
- 一个题目以及自己写的程序,求指导一下
- 自己python写的程序
- 自己写的一个导出的程序这里主要用到一下程序
- 看到别人的Python爬虫博客,自己也模仿着写一个,顺便练习一下python
- 人生的一个小转折点,mark一下
- 前一段时间没事用c#写了一个串口程序,这里总结一下自己的经验
- mark一下逆向c++写的dll的套路
- mark一下逆向c++写的dll的套路
- 自己写的一个JSP小游戏21点,记录一下
- 写一个随笔,总结一下自己的工作
- 记录一下-自己写的一个项目夭折了
- 好气 写了半天的效果 蚂蜂网动画
- 自己写的一个ping程序
- 自己写的一个分页程序
- 自己写的一个分页程序
- NAS介绍
- NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext
- Dubbo配置文件
- Mysql-(Mysql5.7及以上版本)Access denied for user 'root'@'localhost' (using password:YES) 解决方案
- Hive 表增删改查CRUD操作
- 自己写的一个爬蚂蜂窝的景点数据的Python程序,Mark一下
- Linux的Docker上安装MySQL记录
- sysfs系统--文件和目录的创建
- Android上展示word、excel、pdf、ppt~
- ios-自动布局约束的问题
- Python--ImportError: No module named media
- android开发笔记之APK反编译(二) jadx
- User root is not allowed to impersonate anonymous
- 用户界面交互计算圆的周长和面积