最近因项目需要用到python处理网页,因此学习相关知识。下面程序使用python抓取网页并提取信息,具体内容如下:
#
import urllib2 #extensible library for opening URLs
import re #regular module
#
def main():
userMainUrl = "http://www.songtaste.com/user/351979/"
req = urllib2.Request(userMainUrl) #request
resp = urllib2.urlopen(req) #response
respHtml = resp.read() #read html
print "respHtml =", respHtml
#
crifan
foundH1user = re.search(r'
(?P.+?)
', respHtml)print "foundHluser =", foundH1user
if foundH1user:
h1user = foundH1user.group("h1user")
print "hluser=", h1user
###################################################################################
if __name__=='__main__':
mai