When learning Python, you need to pay attention to related matters. First, You Need To Know What Python is when learning Python? So what is Python, the so-called Python: it is an object-oriented, literal-translation computer programming language, and also a powerful and complete general-purpose language.
At present, we need to convert a declarative HTML page into a PORTAL. Because of the large number of pages, we adopt Dynamic rewriting. The purpose of this article is not to introduce our project. So let's talk about my script directly. Because of our work, we need to perform simple tag Analysis on static pages before performing operations. Here we mainly analyze TABLE, TR and TD.
Next, paste my code: Python beginners mainly have two files:
- import os, fnmatch
-
- # judge comment tag to delete comment statement
- def judgeComment (line):
- openTag = line.find('<!--')
- closeTag = line.find('-->')
- if openTag != -1:
- if closeTag != -1:# <!-- -->
- return 1
- else:#<!--
- return 2
- elif closeTag != -1:#-->
- return 3
- else:#
- return 4
-
- # sort for a 2 dimension list(array)
- def sortFor2di (listtosort):
- size = len(listtosort)
- for i in range(size-1):
- for j in range(i + 1,size):
- list1 = listtosort[i]
- list2 = listtosort[j]
- if list1[0] > list2[0]:
- listtosort[i],listtosort[j] = listtosort[j],listtosort[i]
-
- # get all tags in a line in the form of list
- def getLineTagList (line):
- taglist = []
- addTag2List (line,'table',taglist)
- addTag2List (line,'tr',taglist)
- addTag2List (line,'td',taglist)
- sortFor2di (taglist)
- return taglist
-
- def addTag2List (line,tag,taglist):
- pos = line.find('<'+tag)
- if pos != -1:
- taglist.append([pos,'<'+ tag + '>'])
- pos = line.find('</'+tag+'>')
- if pos != -1:
- taglist.append([pos,'</' + tag + '>'])
-
- def addDelTag(itemlist,stackList):
- tag = itemlist[1]
- res = 0
- res += judgeWhichTag (tag,'table',stackList)
- res += judgeWhichTag (tag,'tr',stackList)
- res += judgeWhichTag (tag,'td',stackList)
- if res != 0:
- return -1
- else:
- return 1
-
- #
- def judgeWhichTag (tag,lable,stackList):
- if tag == '<' + lable + '>':
- stackList.append(lable)
- return 0
- elif tag == '</' + lable + '>':
- size = len(stackList)
- if size < 1:
- return -1
- elif stackList[size - 1] == lable:
- del(stackList[size -1 ])
- return 0
- else:
- return -1
- else:
- return 0
-
- # used to deal tag
- def tagDeal (tag, line,stackList):
- openTag = line.find('<'+tag)
- closeTag = line.find('</'+tag+'>')
- if openTag != -1:
- stackList.append (tag)
- if closeTag == -1:
- return 1
- if closeTag != -1:
- size = len(stackList)
- if size < 1:
- return -1
- else:
- lastItem = stackList[size - 1]
- if lastItem != tag:
- return -1
- else:
- del (stackList[size - 1])
- return 1
-
- def find (pattern,startdir=os.curdir):
- files = []
- os.path.walk(startdir,visitor,(pattern,files))
- files.sort()
- return files
-
- def visitor ((pattern,files),thisdir,names):
- for name in names:
- if fnmatch.fnmatch(name,pattern):
- fullpath = os.path.join(thisdir,name)
- files.append(fullpath)
I'm a beginner in Python. The above program is very messy, and you will have time to modify or add some comments later. Of course, you are welcome to give your comments. However, the final result is that a total of 1000 of our 200 statement pages contain pages. These three labels have errors. This means there are a lot of things to deal. We have not made a decision on how to do it.
- How to embed Python into C ++ applications?
- In-depth discussion of Ruby and Python syntax comparison
- Introduction to Python
- Python Learning Experience: version, IDE selection and coding Solutions
- Analysis of Python GIL and thread security