mam*_*eri 14 python beautifulsoup html-parsing
我正在进入一个包含我想要的所有行的for循环:
page = urllib2.urlopen(pageurl)
soup = BeautifulSoup(page)
tables = soup.find("td", "bodyTd")
for row in tables.findAll('tr'):
Run Code Online (Sandbox Code Playgroud)
在这一点上,我有我的信息,但是
<br />
Run Code Online (Sandbox Code Playgroud)
标签毁了我的输出.
删除这些最简洁的方法是什么?
Mu *_*ind 19
如果你想将<br />'s 转换为换行符,请执行以下操作:
def text_with_newlines(elem):
text = ''
for e in elem.recursiveChildGenerator():
if isinstance(e, basestring):
text += e.strip()
elif e.name == 'br':
text += '\n'
return text
Run Code Online (Sandbox Code Playgroud)
Kab*_*bie 16
for e in soup.findAll('br'):
e.extract()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19806 次 |
| 最近记录: |