怎样采用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)
2年前 评论
rz0112 (楼主) 2年前