使用python获取html页面的内容
import urllib
from HTMLParser import HTMLParser
class TitleParser(HTMLParser):
def __init__(self):
self.title = ''
self.divcontent = ''
self.readingtitle = 0
self.readingdiv = 0
HTMLParser.__init__(self)
def handle_starttag(self, tag, attrs):
if tag == 'title':
self.readingtitle = 1
if -1 != tag.find("div"):
self.readingdiv = 1
def handle_data(self, data):
if self.readingtitle:
# Ordinarily, this is slow and a bad practice, but
# we can get away with it because a title is usually
# small and simple.
self.title += data
if self.readingdiv:
self.divcontent += data
def handle_endtag(self, tag):
if tag == 'title':
self.readingtitle = 0
if tag == "div":
self.readingdiv = 0
def gettitle(self):
return self.title
def getdiv(self):
return self.divcontent
def getweb(url):
web = urllib.urlopen('http://blog.chinaunix.net/u3/105068/showart_2223566.html').read()
return web
web = getweb('http://blog.chinaunix.net/u3/105068/showart_2223566.html')
test = TitleParser()
test.feed(web)
file_object = open('abinfile', 'w')
file_object.write(test.title)
file_object.write("\r\n")
file_object.write(test.divcontent)
file_object.close()
相关文档:
标准事件属性
HTML 4 增加了通过事件触发浏览器中行为的能力,比如当用户点击某个元素时启动一段 JavaScript。
如果需要学习更多有关使用这些事件进行编程的内容,请学习我们的 JavaScript 教程 和 DHTML 教程。
下面的表格列出了可插入 HTML 5 元素中以定义事件行为的标准事件属性。
HTML 4.01 与 HTML 5 之间的差异 ......
#filename Seek.py
import unicodedata
import sys
import os
class Seek():
"""
功能:查找中文,并替换成指定字符或字符串
使用方法:python脚本用法
参数说明:
-d& ......
1、str类型可以理解为一个二进制block,或multibyte
2、multibyte_str.decode("<multibyte_encode_method>") -> unicode
3、unicode_str.encode("<multibyte_encode_method>") -> multibyte_str(binary block)
4、unicode_str 的操作参数也应为unicode,如:unicode_str.find("样本".deco ......
A client asked me to do something seemingly simple.
"I want the Alert to have just this one sentence bolded."
Well, it's not exactly simple, so here's how you do it:
there are two solutions as below :
import mx.core.IUITextField;
use namespace mx.core.mx_internal;
message +="Press ......
前两天理解了unicode、utf-8、gb2312这些编码之间的关系以后,今天终于弄明白了在python里面的编码问题。我们在写python脚本时如果有中文的字符串,在运行的时候有可能会报错也有可能会出现乱码。一般加上# -*- coding:utf-8 -*-就不会报错了,但是还可能有乱码问题,而且同样的代码在不同的编辑器中得出的结果 ......