Python 删除额外文本
这让我知道如果他在线,我只想知道他的名字,我该怎么做?如果你能确保结构与你发布的类似,你可以使用以下代码:Python 删除额外文本,python,beautifulsoup,bs4,Python,Beautifulsoup,Bs4,这让我知道如果他在线,我只想知道他的名字,我该怎么做?如果你能确保结构与你发布的类似,你可以使用以下代码: for div in soup.findAll("div", class_="friendBlockContent", ): print(div) 如果可以确保结构与发布的结构相似,则可以使用以下代码: for div in soup.findAll("div", class_="friendBlockContent", ): print(div) div有两个
for div in soup.findAll("div", class_="friendBlockContent", ):
print(div)
如果可以确保结构与发布的结构相似,则可以使用以下代码:
for div in soup.findAll("div", class_="friendBlockContent", ):
print(div)
div
有两个文本节点,您可以使用.strings
访问,并使用.stripped\u strings
获取干净的数据。
然后使用name
和online
字段解压这两个节点
for div in soup.findAll("div", class_="friendBlockContent", ):
print(div.contents[0].strip())
div
有两个文本节点,您可以使用.strings
访问,并使用.stripped\u strings
获取干净的数据。
然后使用name
和online
字段解压这两个节点
for div in soup.findAll("div", class_="friendBlockContent", ):
print(div.contents[0].strip())
实现这一目标的好方法是:
In [50]: for div in soup.findAll("div", class_="friendBlockContent", ):
...: name, online = div.stripped_strings
...:
In [51]: name
Out[51]: 'Bartdavy'
In [52]: online
Out[52]: 'Online'
实现这一目标的好方法是:
In [50]: for div in soup.findAll("div", class_="friendBlockContent", ):
...: name, online = div.stripped_strings
...:
In [51]: name
Out[51]: 'Bartdavy'
In [52]: online
Out[52]: 'Online'
可能的重复可能的重复