我在 div 标记中有这个文本块,但我不需要文本的前10行和最后10行。如何在不创建任何临时文件的情况下执行此操作? 目前,我阅读和编写内容的简单代码是:
soup = BeautifulSoup(r.text)
x = soup.find("div", {"class": "content"})
x = x.text
f = open('test.txt', 'wb')
f.write(x.encode('utf-8'))
HTML代码中的文本块:
<div class="content">
<div class="heading">result</div>
<p class="sub-heading2">CSE</p>
<div class="content" style="font-family:courier">
UNIVERSITY <br />
<br />
GRADE SHEET - NOV/DEC 2014 EXAMINATIONS. <br />
<br />
Subject Code : CSE504<br />
Subject Title : SOFTWARE ENGINEERING<br />
Subject Credit : 4.0 <br />
<br />
REGNO INT UM TOT GRADE<br />
2037 13.30 AB 0.00 I<br />
2029 15.40 10 26.00 F<br />
2018 19.90 29.5 50.00 D<br />
2020 22.60 30 53.00 C<br />
2029 26.40 18.5 45.00
No. of Malpractices = 0<br />
No. of Detentions = 1<br />
No. of NA = 0<br />
No. of students appeared = 113<br />
</div></div></div>
我只需要代码中间的表格,即REGNO INT TOT GRADE表格。