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

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

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

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

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

#!/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)

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論