Python 删除空白行和空白

Python 删除空白行和空白,python,beautifulsoup,blank-line,Python,Beautifulsoup,Blank Line,我曾尝试在这个网站上、网络上和谷歌集团上寻找一个解决方案,但没有成功。我认为问题在于我试图在空数据名上运行函数。我只想删除空白线和空白空间周围的数据从网页出来。谢谢你的帮助 这是我的密码: import requests from bs4 import BeautifulSoup from django.core.management.base import BaseCommand, CommandError class Command(BaseCommand): help = 'Pull

我曾尝试在这个网站上、网络上和谷歌集团上寻找一个解决方案,但没有成功。我认为问题在于我试图在空数据名上运行函数。我只想删除空白线和空白空间周围的数据从网页出来。谢谢你的帮助

这是我的密码:

import requests
from bs4 import BeautifulSoup
from django.core.management.base import BaseCommand, CommandError

class Command(BaseCommand):
  help = 'Pull Data from RR web'

  def handle(self, *args, **options):
    page = requests.get('https://www.radioreference.com/apps/db/?sid=201&opt=all_tg#tgs')
    soup = BeautifulSoup(page.text, 'html.parser')
    rr_name_list = soup.find(class_='titlebox')
    rr_name_list_items = rr_name_list.find_all('td')

    for rr_name in rr_name_list_items:
      names = rr_name.contents[0].strip()
      print "".join(line for line in names if not line.isspace()
      print(names)
这是我的错误:

NameError: name 'NavigableString' is not defined
print "".join(line for line in names if not line.isspace())
^
SyntaxError: invalid syntax

打印需要括号,请尝试
print(blah)
谢谢!这修复了第一个语法错误,但现在我得到了这个,我认为这意味着在某个点上没有数据来自名称。names=rr_name.contents[0]。strip()类型错误:“NoneType”对象不可调用