让窗口支持拖放(文件,文本,URL...)
2009-08-16 13:07
357 查看
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe> 1. 用urllib2/sgmllib包,将目标网页的所有URL列出。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
importurllib2
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
fromsgmllibimportSGMLParser
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
classURLLister(SGMLParser):
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
defreset(self):
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
SGMLParser.reset(self)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
self.urls=[]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
defstart_a(self,attrs):
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
href=[vfork,vinattrsifk=='href']
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ifhref:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
self.urls.extend(href)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
f=urllib2.urlopen("http://icode.csdn.net")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
iff.code==200:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
parser=URLLister()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
parser.feed(f.read())
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
f.close()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
forurlinparser.urls:printurl
2. 使用BeautifulSoup分析数据
http://www.crummy.com/software/BeautifulSoup/,这里有很详细的文档
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
importurllib2
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
fromsgmllibimportSGMLParser
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
classURLLister(SGMLParser):
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
defreset(self):
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
SGMLParser.reset(self)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
self.urls=[]
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
defstart_a(self,attrs):
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
href=[vfork,vinattrsifk=='href']
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ifhref:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
self.urls.extend(href)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
f=urllib2.urlopen("http://icode.csdn.net")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
iff.code==200:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
parser=URLLister()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
parser.feed(f.read())
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
f.close()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
forurlinparser.urls:printurl
2. 使用BeautifulSoup分析数据
http://www.crummy.com/software/BeautifulSoup/,这里有很详细的文档
相关文章推荐
- 让窗口支持拖放(文件,文本,URL...)
- IDropTarget 封装 让窗口支持拖放(文件,文本,URL...)
- 使用IDropTarget接口同时支持文本和文件拖放(二)
- Delphi使窗口支持文件拖放的简单例子,附源代码
- [VC]使用IDropTarget接口同时支持文本和文件拖放(1)(zt)
- 使用IDropTarget接口同时支持文本和文件拖放
- 使用IDropTarget接口同时支持文本和文件拖放
- 使用IDropTarget接口同时支持文本和文件拖放
- 使用IDropTarget接口同时支持文本和文件拖放(一)
- 使用IDropTarget接口同时支持文本和文件拖放
- Delphi使窗口支持文件拖放的简单例子,附源代码
- [ATL/WTL]_[初级]_[拖放文件到窗口]
- C#文件拖放至窗口的ListView控件获取文件类型
- 自制支持文件拖放的VCL组件
- 【随笔★URL重写】让Intelligencia.UrlRewriter.dll支持独立的配置文件
- 5G的文本TXT文件,按行存放URL,去重
- 工作中碰到的一些东西【弹出窗口】【拖放】【异步文件上传】
- Java 通过URL地址下载文本内容到本地文件中
- net控件中数据导到Excel的格式 首先,我们了解一下excel从web页面上导出的原理。当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。下面就列出常用的一些格式: 1) 文本
- HTML5 File API初探 支持文件拖放上传功能