python urlopen
Python urllib 库提供了一个从指定的 URL 地址获取网页数据,然后对其进行分析处理,获取想要的数据。
urlopen返回 一个类文件对象(fd),它提供了如下方法:
read() , readline() , readlines() , fileno() , close() :这些方法的使用方式与文件对象完全一样;
info():返回一个httplib.HTTPMessage 对象,表示远程服务器返回的头信息(header)
getcode():返回Http状态码。如果是http请求,200表示请求成功完成;404表示网址未找到;
geturl():返回请求的url;
from urllib.request import urlopen
import json
from pprint import pprint
u=urlopen('https://www.baidu.com/').read() #get all content on url page
u1=urlopen('https://www.baidu.com/')
print(u1.info()) #get header information from remote server
print(u1.getcode())#get status code
print(u1.geturl())#get request url
python urlopen的更多相关文章
- python urlopen SSL: CERTIFICATE_VERIFY_FAILED
1.使用ssl创建未经验证的上下文,在urlopen中传入上下文参数 import sslimport urllib2 context = ssl._create_unverified_context ...
- 关于python urlopen 一个类似radio流的timeout方法
终极解决方法来啦!看代码感受: import requests import eventlet import time eventlet.monkey_patch() try: with eventl ...
- python运行报错:urllib2.URLError: <urlopen error [Errno 10061] >
Traceback (most recent call last): File "F:\adt-bundle-windows-x86_64-20140702\eclipse\workspac ...
- python urllib模块的urlopen()的使用方法及实例
Python urllib 库提供了一个从指定的 URL 地址获取网页数据,然后对其进行分析处理,获取想要的数据. 一.urllib模块urlopen()函数: urlopen(url, data=N ...
- Python中urlopen()介绍
#以下介绍是基于Python3.4.3 一. 简介 urllib.request.urlopen()函数用于实现对目标url的访问. 函数原型如下:urllib.request.urlopen( ...
- Python基础之 urllib模块urlopen()与urlretrieve()的使用方法详解。
Python urllib模块urlopen()与urlretrieve()的使用方法详解 1.urlopen()方法urllib.urlopen(url[, data[, proxies]]) ...
- Python 2.7.3 urllib2.urlopen 获取网页出现乱码解决方案
出现乱码的原因是,网页服务端有bug,它硬性使用使用某种特定的编码方案,而并没有按照客户端的请求头的编码要求来发送编码. 解决方案:使用chardet来猜测网页编码. 1.去chardet官网下载ch ...
- 【转】【Python】python使用urlopen/urlretrieve下载文件时出现403 forbidden的解决方法
第一:urlopen出现403 #!/usr/bin/env python # -*- coding: utf- -*- import urllib url = "http://www.go ...
- Python爬虫教程-02-使用urlopen
Spider-02-使用urlopen 做一个最简单的python爬虫,使用爬虫爬取:智联招聘某招聘信息的DOM urllib 包含模块 - urllib.request:打开和读取urls - ur ...
随机推荐
- python面向对象的三大特性
一.继承 面向对象中的继承就是继承的类直接拥有被继承类的属性而不需要在自己的类体中重新再写一遍,其中被继承的类叫做父类.基类,继承的类叫做派生类.子类.在python3中如果不指定继承哪个类,默认就会 ...
- JavaScript学习(五)
- aws小结
IAM:亚马逊访问权限控制(AWS Identity and Access Management ) https://www.cnblogs.com/andy9468/p/10635019.html ...
- dxRatingControl使用
Properties AllowHover:是否鼠标滑动选择 CheckedGlyph:选中后显示的图像 Glyph:显示的图像 HoverGlyph:鼠标滑动时显示的图像 ItemCount:项目总 ...
- python实时得到鼠标的位置
1.#先下载pyautogui库,打开cmd输入pip install pyautogui,回车 2.代码如下: import os,time import pyautogui as pag try: ...
- abp中linq的应用
private IQueryable<MembershipEntity> SelectOrScrrenMember(GetMemberInput input) { string[] use ...
- 2019.03.23 Http
自己也要分清楚 看清楚 request,response 一个是请求 一个是相应 行 头 之间还有个空行 体 HttpRequest请求对象(只读) 当用户访问一个视图函数时,Djan ...
- AFNetworking 源码解析
3.0 之后,就取消了NSOperation的控制. 因为根据Apple Developer Document的文档 https://developer.apple.com/documentation ...
- 学习笔记 python 面向对象学习
封装: 封装是面向对象的特征之一,是对象和类概念的主要特性. 封装,也就是把客观事物封装成抽象的类,并且类可以把自己的数据和方法只让可信的类或者对象操作,对不可信的进行信息隐藏. 继承: 继承是指这样 ...
- express-generator 自动生成服务器基本文件
(1) 安装 express-generator 构建工具 npm install -g express-generator 在命令行中用 npm 在全局安装 express-generator 脚手 ...