要解决这个问题,您可以使用strip()方法去除字符串变量末尾的换行符。下面是一个示例代码:
from bs4 import BeautifulSoup
# 假设row是一个BeautifulSoup对象中的某个元素
row = BeautifulSoup("Example\n", "html.parser")
# 使用find方法查找元素,并使用strip()去除换行符
text = row.find("div").text.strip()
# 打印结果
print(text)
输出结果将是:Example
,而不是Example\n
。