欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實現(xiàn)根據(jù)用戶輸入從電影網(wǎng)站獲取影片信息的方法

 更新時間:2015年04月07日 12:28:31   作者:令狐不聰  
這篇文章主要介紹了python實現(xiàn)根據(jù)用戶輸入從電影網(wǎng)站獲取影片信息的方法,涉及Python正則表達式抓取網(wǎng)頁的技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了python實現(xiàn)根據(jù)用戶輸入從電影網(wǎng)站獲取影片信息的方法。分享給大家供大家參考。具體如下:

這段python代碼主要演示了用戶終端輸入,正則表達式,網(wǎng)頁抓取等

#!/usr/bin/env python27
#Importing the modules
from BeautifulSoup import BeautifulSoup
import sys
import urllib2
import re
import json
#Ask for movie title
title = raw_input("Please enter a movie title: ")
#Ask for which year
year = raw_input("which year? ")
#Search for spaces in the title string
raw_string = re.compile(r' ')
#Replace spaces with a plus sign
searchstring = raw_string.sub('+', title)
#Prints the search string
print searchstring
#The actual query
url = "http://www.imdbapi.com/?t=" + searchstring + "&y="+year
request = urllib2.Request(url)
response = json.load(urllib2.urlopen(request))
print json.dumps(response,indent=2)

希望本文所述對大家的Python程序設計有所幫助。

相關文章

最新評論