python3抓取中文网页的方法

yipeiwu_com5年前Python爬虫

本文实例讲述了python3抓取中文网页的方法。分享给大家供大家参考。具体如下:

#! /usr/bin/python3.2
import sys
import urllib.request
req = urllib.request.Request('http://www.baidu.com')
response = urllib.request.urlopen(req)
the_page = response.read()
type = sys.getfilesystemencoding()
#转换成本地系统编码
print(the_page.decode(type))

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python爬取数据并写入MySQL数据库的实例

Python爬取数据并写入MySQL数据库的实例

首先我们来爬取 http://html-color-codes.info/color-names/ 的一些数据。 按 F12 或 ctrl+u 审查元素,结果如下: 结构很清晰简单,...

python3.4爬虫demo

python 3.4 所写爬虫 仅仅是个demo,以百度图片首页图片为例。能跑出图片上的图片; 使用 eclipse pydev 编写: from SpiderSimple.HtmL...

使用python实现抓取腾讯视频所有电影的爬虫

用python实现的抓取腾讯视频所有电影的爬虫 # -*- coding: utf-8 -*- import re import urllib2 from bs4import Bea...

python可视化爬虫界面之天气查询

python可视化爬虫界面之天气查询

执行效果如下: from tkinter import * import urllib.request import gzip import json from tkinter...

零基础写python爬虫之爬虫的定义及URL构成

一、网络爬虫的定义网络爬虫,即Web Spider,是一个很形象的名字。把互联网比喻成一个蜘蛛网,那么Spider就是在网上爬来爬去的蜘蛛。网络蜘蛛是通过网页的链接地址来寻找网页的。从网站...