Python 如何使用BeautifulSoup解析表?

Python 如何使用BeautifulSoup解析表?,python,parsing,beautifulsoup,Python,Parsing,Beautifulsoup,这是一个特定于上下文的问题,涉及如何在python2.7中使用BeautifulSoup解析html表 我想提取html表并将其放在tab delim csv中,并尝试使用BeautifulSoup 上下文代码: proxies = { "http://": "198.204.231.235:3128", } site = "http://sloanconsortium.org/onlineprogram_listing?page=11&Institution=&fiel

这是一个特定于上下文的问题,涉及如何在python2.7中使用BeautifulSoup解析html表

我想提取html表并将其放在tab delim csv中,并尝试使用BeautifulSoup

上下文代码:

proxies = {
    "http://": "198.204.231.235:3128",
}
site = "http://sloanconsortium.org/onlineprogram_listing?page=11&Institution=&field_op_delevery_mode_value_many_to_one[0]=100%25%20online"

r = requests.get(site, proxies=proxies)
print 'r: ', r
html_source = r.text
print 'src: ', html_source
soup = BeautifulSoup(html_source)
为什么这段代码没有排到第四行

soup.find('table','views-table cols-6').tr[4]

如何打印出第一行(而不是标题行)中的所有元素?

好的,也许有人能给你一行,但下面应该让你开始

table = soup.find('table', class_='views-table cols-6')                                                                                                                                                                                                                        
for row in table.find_all('tr'):                                                                                                                                                                                                                                               
    row_text = list()                                                                                                                                                                                                                                                          
    for item in row.find_all('td'):                                                                                                                                                                                                                                            
        text = item.text.strip()                                                                                                                                                                                                                                               
        row_text.append(text.encode('utf8'))                                                                                                                                                                                                                                   
    print row_text
我相信你的tr[4]被认为是一个属性,而不是你想象中的索引