如何用python解析网页并获得网页真实的源码

如题所述

Python 2.7版本的话 代码如下:

#!/usr/bin/env python
# -*- coding:utf8 -*-
import urllib
import urllib2
import string
import re

addr1 = 某个网址的地址(string format)
response1 = urllib.urlopen(addr1)
text1 = response1.read()
response1.close()

text1就是网页的源代码,可以print出来看。UTF8的代码是为了确保能正确抓取中文。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答