python爬取廖雪峰javascript教程
来源:互联网 发布:suse linux设置网络 编辑:程序博客网 时间:2024/06/03 01:45
这篇文章和我上一篇的爬取廖雪峰python3教程一样,只是用到了一些不一样的东西,在下面的学习中还是会定时更新一些东西供大家阅读
#coding:utf-8import requests,lxml,os,sys,codecsfrom bs4 import BeautifulSoupdef get_url(url): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'} re=requests.get(url,headers=headers) html=re.text all_url=[] soup=BeautifulSoup(html,'lxml') all_a=soup.find('div',class_='x-sidebar-left-content').find_all('a') for a in all_a: all_url.append('http://www.liaoxuefeng.com' + a.get('href')) return all_urldef get_text(all_url): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'} for url in all_url: re=requests.get(url,headers=headers) html=re.text soup=BeautifulSoup(html,'lxml') all_h4 = soup.find_all('h4') div = soup.find('div', class_='x-wiki-content') content=all_h4[0].text+div.text if all_h4[0].text=='map/reduce': #这是判断里面的名字可能和路径相冲突 filename=os.path.normpath('g:\\file\\'+'map and reduce'+'.js') else: filename=os.path.normpath('g:\\file\\'+all_h4[0].text+'.js') print u'正在下载' + all_h4[0].text with codecs.open(filename, 'w', encoding='utf-8') as f: # 将信息写入py文件中 f.write(content)if __name__=="__main__": url='http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000' all_url=get_url(url) get_text(all_url)
0 0
- python爬取廖雪峰javascript教程
- Python爬取廖雪峰Python教程
- 廖雪峰JavaScript教程
- python爬取廖雪峰的python3教程
- 廖雪峰python教程
- JavaScript教程_廖雪峰
- 廖雪峰的Python教程
- Python练习 - 廖雪峰教程
- 廖雪峰 Python教程 笔记
- 廖雪峰python教程之python基础
- 廖雪峰javascript教程学习笔记
- 廖雪峰的Git、Python教程
- 廖雪峰的0Python教程
- 廖雪峰的Python教程-网络编程
- 廖雪峰的Python教程-电子邮件
- 廖雪峰Python教程学习笔记
- 廖雪峰python教程笔记01
- 廖雪峰python教程学习笔记02
- ThinkPhp3.2 无法加载模块:Index
- linux install go & gogs &git
- Android项目实践之菜鸟养成 (三)Android简单页面跳转
- Spring Boot中使用JdbcTemplate访问数据库
- 4sum
- python爬取廖雪峰javascript教程
- tolua注册对象到lua,并在lua中调用的实现
- (经验技巧)Axure 方法 切换if/else if”
- ADT语音算法软件简介
- 烹饪实验问题归约3SAT问题| NP-完全问题归约
- webservice开发三:CXF+Spring开发WebService
- ECMAScript 6(1)Babel
- ftp和ftps的理解(一)
- C++学习笔记-----在一个构造函数中调用另一个构造函数