Nitro’s
  • Tech
  • Android
  • Linux
  • Life
  • Travel
  • Github
  • About

Python

A collection of 1 post
Python

Python 网页解析笔记(一)

语言版本:Python 2.7 函数库:urllib2、chardet、BeautifulSoup 示例代码如下: import urllib2 import chardet from bs4 import BeautifulSoup ​ data = urllib2.urlopen('http://www.nitrohsu.com').read() encodeStr = chardet.detect(a)['encoding'] soup=BeautifulSoup(data,from_encoding=encodeStr) ​ print soup.prettify -------------------------------------------------------------------------------- chardet是一个自动检测网页编码的函数,调用detect会返回一个字典: {'confidence': 0.
12 Mar 2013 1 min read
Page 1 of 1
Nitro’s © 2025
Powered by Ghost