怎样采用split或正则表达式分割不规格空格分隔符?

from pyquery import PyQuery as pq
html=’www.autohome.com.cn/liuzhou/#pvare...
dc=pq(html)
t=dc(‘.ranking-block.ranking-block–sale .ranking-block__item .ranking-block__info p:nth-of-type(1)’).text()
print(t)

#打印出的结果为:

#宏光MINIEV Model Y 轩逸 宋PLUS新能源 Model 3 秦PLUS 凯美瑞 朗逸 雷凌 哈弗H6

#请问如何得到结果:

#[‘宏光MINIEV’, ‘Model Y’, ‘轩逸’, ‘宋PLUS新能源’, ‘Model 3’, ‘秦PLUS’, ‘凯美瑞’, ‘朗逸’, ‘雷凌’, ‘哈弗H6’]

讨论数量: 2
Jason990420

Not sure if it work for your case.

items = dc(.ranking-block.ranking-block–sale .ranking-block__item .ranking-block__info p:nth-of-type(1))
lst = list(items.map(lambda i, e:pq(this).text()))
print(lst)
1年前 评论
rz0112 (楼主) 1年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!