【问题标题】:How to get partial text from html in Python如何在 Python 中从 html 中获取部分文本
【发布时间】:2013-10-17 15:19:03
【问题描述】:

我正在尝试使用BeautifulSoup 从以下html 获取一些文本:

test = '''<p class="author"><a href="./viewtopic.php?p=1829610"></a>by <strong>FinancialDave</a></strong> Thu Oct 17, 2013 12:52 am </p>'''
testsoup = BeautifulSoup(test)
testsoup.text

这会给我这样的结果:u'by FinancialDave Thu Oct 17, 2013 12:52 am

但是我想要的只是Thu Oct 17, 2013 12:52 am。有什么办法吗?

提前致谢。

【问题讨论】:

  • 上下文信息不足。您为什么不简单地手动复制和粘贴日期?

标签: python html beautifulsoup


【解决方案1】:

您需要使用正则表达式提取日期字符串。 BeautifulSoup 在这里帮不了你。

【讨论】:

    猜你喜欢
    • 2019-04-10
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多