php抓取网页表格信息( Python程序设计有所抓取网页的技巧(2015年04月07日12:31))
优采云 发布时间: 2022-04-10 06:39php抓取网页表格信息(
Python程序设计有所抓取网页的技巧(2015年04月07日12:31))
python实现了一种从电影中获取电影信息的方法网站根据用户输入
更新时间:2015-04-07 12:28:31 作者:令狐步聪
本文文章主要介绍python根据用户输入从电影网站中获取电影信息的方法,涉及到用Python正则表达式抓取网页的技术,非常实用价值。有需要的朋友可以参考以下
本文中的例子描述了python根据用户输入从movie网站中获取电影信息的方法。分享给大家,供大家参考。详情如下:
这段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 编程有所帮助。