python爬蟲裡的換行prettify
阿新 • • 發佈:2018-12-22
>>> print(soup.p.prettify) <bound method Tag.prettify of <p class="title"><b>The demo python introduces several python courses.</b></p>> >>> print(soup.p.prettify()) <p class="title"> <b> The demo python introduces several python courses. </b> </p> >>> print(soup.html.prettify()) <html> <head> <title> This is a python demo page </title> </head> <body> <p class="title"> <b> The demo python introduces several python courses. </b> </p> <p class="course"> Python is a wonderful general-purpose programming language. You can learn Python from novice to professional by tracking the following courses: <a class="py1" href="http://www.icourse163.org/course/BIT-268001" id="link1"> Basic Python </a> and <a class="py2" href="http://www.icourse163.org/course/BIT-1001870001" id="link2"> Advanced Python </a> . </p> </body> </html> >>> print(soup.head.prettify()) <head> <title> This is a python demo page </title> </head> >>>
工作原理,在原來的文本里加入了換行符:“\n”。就可以進行換行,使得程式一目瞭然!
圖片比例不對,就用放大鏡檢視!