现在回到了文件的开始之处,可以把文件内容读入 string 变量并对 string 做适当地解析。
Now that you're back to the start of the file, you can read the file contents into a string variable and parse the contents of the string appropriately.
您一开始可能觉得这很奇怪,但是最终会发现这种机制是十分强大的,因为不管某篇待处理的文档中包含多少缩进,您都可以确切地看出文档解析之后将会是什么样子。
This may seem odd at first, but it turns out to be very powerful — you can see exactly what the document being parsed looks like, including any indenting!
首先,它可以用作html解析器,只要碰到开始的HTML标记都会提供一个回调方法(handle_starttag)。
First, it's my HTML parser, with a callback method (handle_starttag) whenever a start HTML tag is encountered.
应用推荐