小编Tim*_*yJC的帖子

在循环中查找美丽的汤返回 TypeError

我正在尝试使用 Beautiful Soup 在 ajax 页面上抓取表格,并使用 TextTable 库以表格形式打印出来。

import BeautifulSoup
import urllib
import urllib2
import getpass
import cookielib
import texttable

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

...

def show_queue():
    url = 'https://www.animenfo.com/radio/nowplaying.php'
    values = {'ajax' : 'true', 'mod' : 'queue'}
    data = urllib.urlencode(values)
    f = opener.open(url, data)
    soup = BeautifulSoup.BeautifulSoup(f)
    stable = soup.find('table')
    table = texttable.Texttable()
    header = stable.findAll('th')
    header_text = []
    for th in header:
        header_append = th.find(text=True)
        header.append(header_append)
    table.header(header_text)
    rows = stable.find('tr')
    for tr in rows:
        cells …
Run Code Online (Sandbox Code Playgroud)

python html-table beautifulsoup html-parsing web-scraping

3
推荐指数
1
解决办法
2万
查看次数