python : BeautifulSoup 网页 table 解析范例

BeautifulSoup 网页中 table 解析范例

soupTable.py

# -*- coding: cp936 -*-
import urllib
import urllib2
import os, re
from BeautifulSoup import BeautifulSoup

URL = "?"
page = urllib2.urlopen(URL)
soup = BeautifulSoup(page)
page.close()

tables = soup.findAll('table')
tab = tables[0]
for tr in tab.findAll('tr'):
    for td in tr.findAll('td'):
        print td.getText(),
    print
#


你可能感兴趣的:(python)