【问题标题】:how do i remove empty list [duplicate]我如何删除空列表[重复]
【发布时间】:2021-09-27 04:18:18
【问题描述】:
['New Zealand',
 'England',
 'Australia',
 'India',
 'South Africa',
 'Pakistan',
 'Bangladesh',
 'West Indies',
 'Sri Lanka',
 'Afghanistan',
 'Netherlands',
 'Ireland',
 'Oman',
 'Scotland',
 'Zimbabwe',
 'Nepal',
 'UAE',
 'United States',
 'Namibia',
 'Papua New Guinea',
 '',
 '',
 '',
 '',
 team = soup5.find_all("span",class_='u-hide-phablet')

team_name = []

for i in team:

    team_name.append(i.text)

我在网页抓取 icc 前十名的团队 在这个输出中我想删除空列表请帮助我

【问题讨论】:

    标签: python beautifulsoup python-requests


    【解决方案1】:

    使用if i:

    for i in team:
        if i:
            team_name.append(i.text)
    

    如果这不起作用,请使用:

    for i in team:
        if i.text:
            team_name.append(i.text)
    

    【讨论】:

    • @bishwajitbhattacharya 如果可行,请点击接受标记✔️接受它。
    • 嗯,维基?这是骗人的。
    猜你喜欢
    • 2021-02-12
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多