您的位置:首页 > 编程语言 > Python开发

python网页提取

2016-06-05 23:05 369 查看
#!/usr/bin/python

# -*- coding: utf-8 -*-

#encoding=utf-8

#Filename:urllib2-header.py

  

import urllib2

import sys

  

url = 'http://notepad.cc/share/W7Cgs95rxW'

  

req = urllib2.Request(url)

#req.add_header('Referer','http://notepad.cc/lianghui')

req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.2; rv:16.0) Gecko/20100101 Firefox/16.0')

r = urllib2.urlopen(req)

html = r.read()

receive_header = r.info()

  

html = html.decode('utf-8').encode(sys.getfilesystemencoding())

  

#print receive_header

#print '#####################################'

print html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python urllib2