python实现根据用户输入从电影网站获取影片信息的方法


Posted in Python onApril 07, 2015

本文实例讲述了python实现根据用户输入从电影网站获取影片信息的方法。分享给大家供大家参考。具体如下:

这段python代码主要演示了用户终端输入,正则表达式,网页抓取等

#!/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程序设计有所帮助。

Python 相关文章推荐
python读取TXT到数组及列表去重后按原来顺序排序的方法
Jun 26 Python
Python简单实现子网掩码转换的方法
Apr 13 Python
Python设计实现的计算器功能完整实例
Aug 18 Python
python如何对实例属性进行类型检查
Mar 20 Python
利用Python将数值型特征进行离散化操作的方法
Nov 06 Python
python实现邮件发送功能
Aug 10 Python
解决Python命令行下退格,删除,方向键乱码(亲测有效)
Jan 16 Python
Python2和Python3中@abstractmethod使用方法
Feb 04 Python
使用python实现时间序列白噪声检验方式
Jun 03 Python
解决PyCharm无法使用lxml库的问题(图解)
Dec 22 Python
python编写函数注意事项总结
Mar 29 Python
Python各协议下socket黏包问题原理
Apr 12 Python
python中列表元素连接方法join用法实例
Apr 07 #Python
简单介绍Python中的filter和lambda函数的使用
Apr 07 #Python
解析Python中的变量、引用、拷贝和作用域的问题
Apr 07 #Python
在Python中利用Pandas库处理大数据的简单介绍
Apr 07 #Python
详解Python中的join()函数的用法
Apr 07 #Python
Python中用于去除空格的三个函数的使用小结
Apr 07 #Python
简单介绍Python中的len()函数的使用
Apr 07 #Python
You might like
php数据访问之查询关键字
2016/05/09 PHP
PHP实现清除MySQL死连接的方法
2016/07/23 PHP
PHP二维数组去重算法
2016/12/17 PHP
ThinkPHP5+Layui实现图片上传加预览功能
2018/08/17 PHP
ThinkPHP5分页paginate代码实例解析
2020/11/10 PHP
jquery选择器(常用选择器说明)
2010/09/28 Javascript
Jquery阻止事件冒泡 event.stopPropagation
2011/12/11 Javascript
jquery中子元素和后代元素的区别示例介绍
2014/04/02 Javascript
jquery实现点击label的同时触发文本框点击事件的方法
2015/06/05 Javascript
jquery实现表格中点击相应行变色功能效果【实例代码】
2016/05/09 Javascript
Markdown+Bootstrap图片自适应属性详解
2016/05/21 Javascript
JS实现n秒后自动跳转的两种方法
2020/11/30 Javascript
Vue.js第二天学习笔记(vue-router)
2016/12/01 Javascript
JavaScript实现三级联动效果
2017/07/15 Javascript
详解Node全局变量global模块
2017/09/28 Javascript
利用10行js代码实现上下滚动公告效果
2017/12/08 Javascript
判断文字超过2行添加展开按钮,未超过则不显示,溢出部分显示省略号
2019/04/28 Javascript
解决vue自定义全局消息框组件问题
2019/11/22 Javascript
python通过urllib2爬网页上种子下载示例
2014/02/24 Python
python中函数总结之装饰器闭包详解
2016/06/12 Python
Python实现SMTP发送邮件详细教程
2021/03/02 Python
EM算法的python实现的方法步骤
2018/01/02 Python
python射线法判断一个点在图形区域内外
2019/06/28 Python
在python中用print()输出多个格式化参数的方法
2019/07/16 Python
TensorBoard 计算图的查看方式
2020/02/15 Python
Python图片处理模块PIL操作方法(pillow)
2020/04/07 Python
使用opencv识别图像红色区域,并输出红色区域中心点坐标
2020/06/02 Python
Python 实现键盘鼠标按键模拟
2020/11/18 Python
python里glob模块知识点总结
2021/01/05 Python
学生周末长期请假条
2014/02/15 职场文书
缅怀先烈演讲稿
2014/09/03 职场文书
临时租车协议范本
2014/09/23 职场文书
幼师求职自荐信
2015/03/26 职场文书
毕业典礼主持词
2015/06/29 职场文书
Python中rapidjson参数校验实现
2021/07/25 Python
python如何读取和存储dict()与.json格式文件
2022/06/25 Python