Python爬取并分析网页【基本版】
来源:互联网 发布:mac 全屏切换快捷键 编辑:程序博客网 时间:2024/05/14 16:07
#!/usr/bin/python# -*- coding: UTF-8 -*-import urllibfrom pyquery import PyQuery as pqimport codecs# fetch pageprint 'fetch page...'url = 'http://www.7dsw.com/toplastupdate/1.html'resp = urllib.urlopen(url)page = resp.read()page = page.decode('gbk')#get dataprint 'parse page...'doc = pq(page)wanted = doc('#newscontent ul a')n = len(wanted)books = []caps = []i = 0while i<n: bookname = wanted[i].text captitle = wanted[i+1].text books.append(bookname) caps.append(captitle) i+=2print 'save data...'#save data#fp = open('save.txt','wb')fp = codecs.open('intimate.txt','a','utf-8')for i in range(len(books)): fp.write(books[i]) fp.write(",") fp.write(caps[i]) fp.write("\r\n")fp.close()
0 0
- Python爬取并分析网页【基本版】
- Python爬取一个基本的网页
- python 爬取csdn网页并保存博客到本地
- 简单的python爬取网页字符串内容并保存
- python爬取网页
- Python 网页爬取
- Python,分析爬取简单waterfall型网页的部分内容
- python 爬取网页正文
- python 多线程网页爬取
- python爬取网页信息
- python爬取网页图片
- 学习python爬取网页
- Python爬取简单网页
- python爬取网页内容
- python爬取网页图片
- Python爬取网页数据
- Python爬取网页图片
- Python爬取网页图片
- 计算复杂性学习0-图灵机介绍
- Qt之自定义提示框(类似QMessageBox)
- 人脸识别技术大总结(1)——Face Detection & Alignment
- Mybatis 一对一,一对多,多对一,多对多的理解
- EventTrigger接管所有事件导致 在ScrollRect中,点击不能滚动
- Python爬取并分析网页【基本版】
- 练习三1006
- IDEA 主题、字体、编辑区主题、文件编码修改
- 从无到有写一个C#弹球小游戏(完)(附上游戏完成的截图)
- 苹果Mac OS X怎样设置鼠标滚轮滑动的方向/反向
- C++11 中的单例模式
- [剑指offer]栈的压入、弹出序列
- shareprefererences.Editor的apply和commit异同
- LaTex 符号大全