Skip to content

Instantly share code, notes, and snippets.

@imbyron
Last active December 22, 2015 03:49
Show Gist options
  • Save imbyron/6412676 to your computer and use it in GitHub Desktop.
Save imbyron/6412676 to your computer and use it in GitHub Desktop.
用Python的BeautifulSoup模块抓取豆瓣热映电影
#!usr/bin/python
#coding:utf-8
'''
@author:Byron
新浪围脖:http://weibo.com/ziyuetk
'''
import urllib2
from bs4 import BeautifulSoup
print "豆瓣正在热映:"
url = "http://movie.douban.com"
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html)
div_hot = soup.find('div',{"id":"screening"})
for i in div_hot.find_all('li', class_='title'):
movie_title = i.a.get_text()
# movie_title = movie_title.strip() #去除movie_title两边的空格
print movie_title
print "\n豆瓣近期热门:"
div_new = soup.find('div',{"id":"new-movies"})
for i in div_new.find_all('li', class_='title'):
movie_new = i.a.get_text()
print movie_new
@hfutlion
Copy link

hfutlion commented Jul 6, 2014

ddddddd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment