我一直在努力解决这个问题。基本上我需要拆分一个loong HTML列表(显然我不会把它放在这里因为它是fricken大规模)。我尝试了str.split()
方法但你当时只能输入一个参数。所以我找到了re.split()
函数。但!如果我试图拆分它就会发生这种情况,这会让我感到震惊
Traceback (most recent call last):
File "/root/Plocha/FlaskWebsiteHere/Mrcasa_na_C.py", line 34, in <module>
a = re.split(' / |</h3><p>|: 1\) ', something_paragraf[0])
File "/usr/lib/python3.5/re.py", line 203, in split
return _compile(pattern, flags).split(string, maxsplit)
TypeError: expected string or bytes-like object
现在我试图解决这个问题,但没有:/。请帮忙!
SnailingGoat
答案 0 :(得分:0)
也许是这样的?
for (var k = 0; k < Numero.length;k++) {
if ( (Numero[k] % 2) != 0) {
var doppioNumero = Numero[k] * 2;
Numero[k] = doppioNumero;
if ( Numero[k] > 9) {
var nuovoNum = Numero[k] - 9;
Numero[k] = nuovoNum;
}
}
}
输出:
import re
something_paragraf = soup.find_all("div", {"class":"ukolRes"})
# convert 'bs4.element.ResultSet' to `str`
html = ''.join([s.text for s in something_paragraf])
# modify this regex split to suit your needs
# split string on punctuation
multiple_strings = re.split('(?<=[.,!/?]) +',html)
print(multiple_strings)