请问下面这段代码,输出时只显示第一排中文标题,然后就停止了,本人小白,,刚学,很多不懂,大虾求解
import urllib2
import re
from bs4 import BeautifulSoup
def crawl(url):
page = urllib2.urlopen(url)
contents = page.read()
soup = BeautifulSoup(contents)
print(u' 豆瓣电影TOP250:\n 序号 \t影片名\t 评分 \t评价人数 \t 链接 ')
for tag in soup.find_all('tr', class_='item'):
#print tag
m_order = int(tag.find('td', class_='m_order').get_text())
m_name = tag.a.get_text()
m_year = tag.span.get_text()
m_rating_score = float(tag.em.get_text())
m_rating_num = int(tag.find(headers="m_rating_num").get_text())
m_url=str(tag.find('a')).split('"')[1]
#print m_url
print("%s %s %s %s %s %s " % (m_order, m_name, m_year, m_rating_score, m_rating_num,m_url))
if name == 'main':
crawl('http://movie.douban.com/top250?format=text')
添加回答
举报
0/150
提交
取消