我有以下代码。在
html = urllib2.urlopen(
'https://ebet.tab.co.nz/results/CHCG-reslt05070400.html').read()
soup = BeautifulSoup(html)
data = soup.findAll('div', {'class' : 'header bold'})
match = re.search('R', data[0].text)
race_title = data[0].text[(match.start()):]
race_title = str(race_title.strip(' \t\n\r'))
print race_title
我在控制台屏幕上得到的输出如下所示
^{pr2}$我以为strip可以消除SPRINT和C0之间的任何类型的空格,但显然我遗漏了一些东西,所以我需要帮助来理解这个结果。是因为bs4以unicode格式输出字符串吗?在
通常STRIP只剥离字符串开头和结尾的空格。 使用STR_REPLACE将空格替换为“”。在
strip()
只删除前导字符或尾随字符。如果要删除换行符,应该使用replace("\n","")
相关问题 更多 >
编程相关推荐