python crawler extract url无法正常工作

时间:2016-03-23 03:34:02

标签: python web-crawler imdb

我尝试用imdb包编写一个简单的python程序来从他们的数据库中提取电影信息,但我不知道为什么代码返回空列表。我的猜测是我从网站上提取网址信息(通过使用(。*?))的方式是错误的。我想从网页中提取网址链接。这是代码。谢谢!

import urllib
import re
import imdb
imdb_access = imdb.IMDb()

top_num = 5

movie_list = ["The Matrix","The Matrix","The Matrix","The Matrix","The Matrix"]


for x in xrange(0,top_num):
    contain = imdb_access.search_movie(movie_list[x])

    ID = contain[0].movieID #str type

    htmltext = (urllib.urlopen("http://www.imdb.com/title/tt0133093/?ref_=nv_sr_1")).read()
    # a pattern in the website
    regex = regex = '<img alt="The Matrix Poster" title="The Matrix Poster" src="(.*?)" itemprop="image">'
    pattern = re.compile(regex)
    #print (str((pattern)))
    result = re.findall(pattern,htmltext)
    print result 
    #print type(htmltext)

1 个答案:

答案 0 :(得分:0)

我认为问题在于您可以使用新行(。* \ n *。*?)