Reference Blog: http://www.crifan.com/python_re_search_vs_re_findall/
Here, I'd like to talk about the problems I'm having right now.
This is a local file text.txt
When I use Re.findall () to get its textual content,<li><a href= "http://jikexueyuan.com/1.html" > This is the first article </a></li>
In the content of the <a> tag directly, using the following code, using the first hit after the small principle:<pre name= "code" class= "python" >text_field = Re.findall (' <ul> (. *?) </ul> ', Html,re. S
Text = Re.findall (' "> (. *?) </a></li> ', Text_field,re. S) for each of the Text:print each
It should be fine, but it's a mistake.There was no solution, and then I tried.
1.
Text_field = Re.findall (' <ul> (. *?) </ul> ', Html,re. S) [0]
2.
Text_field = Re.search (' <ul> (. *?) </ul> ', Html,re. S). Group (1) <pre style= "Font-family:consolas; font-size:10.5pt; Background-color:rgb (255, 255, 255); " > Both of these methods are correct
But I don't understand. I had the same feeling when I saw the last mention of the blog at the beginning. At this point, I suspect that when FindAll gets an element that is a tuple, but this tuple has only one, it needs to be given a location like search.
But now I don't know exactly what the situation is to write like this. I hope that the great God will not hesitate to enlighten!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The difference between Re.search and Re.findall in Python