scrap_result = 'Et si on mangeait la connaissance? | Idriss Aberkane | TEDxPanthéonSorbonne' # this is the scrap result of the title you get you can user str() to be precise so you only get string is a title.
scrap_result = scrap_result[:scrap_result.find("|")] # this will give you result before the first occurrence of '|' but it includes trailing space at the end if you want to remove it use scrap_result.strip()
这将提供所需的字符串:
如果你确定每个标题中都有“|”字符,你可以这样写
如果要在第一次出现“|”时删除所有内容,可以编写以下代码:
相关问题 更多 >
编程相关推荐