美丽汤去除空白行和空白

时间:2018-06-27 06:09:21

标签: python beautifulsoup blank-line

我尝试在此网站,网络和Google网上寻找解决方案,以获取没有运气的漂亮汤。我相信问题是我试图在空数据名称上运行函数。我只想删除从网页出来的数据周围的空白行和空白区域。谢谢您的帮助。

这是我的代码:

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

0 个答案:

没有答案