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 ...
随机推荐
- 洛谷P3250 网络 [HNOI2016] 整体二分
正解:整体二分+树状数组 解题报告: 传送门! 亲这里的建议是用整体二分呢 dbq最近看sd淘宝说话体看多了有点脑抽,,, 首先考虑如果是单组询问怎么做昂QAQ 考虑二分答案 对于所有比mid小的操作 ...
- jszip 前端生成zip文件下载
[文档地址] export const ZipFileCreate = () => { Promise.all([ // 下面是引入依赖包 require('jszip'), import('f ...
- mysql创建计算列(5.7以后才有)
mysql创建计算列 mysql> create table t(id int auto_increment not null,c1 int,c2 int,c3 int as (c1+c2) ...
- 线上MYSQL同步报错故障处理方法总结
前言 在发生故障切换后,经常遇到的问题就是同步报错,下面是最近收集的报错信息. 记录删除失败 在master上删除一条记录,而slave上找不到 Last_SQL_Error: Could not e ...
- 并发编程---Process对象的其他属性或方法
Process对象的其他属性或方法 #join方法 from multiprocessing import Process import time,os ''' 需求:让主进程等着子进程运行完毕,才能 ...
- 001-mock.js安装使用
一.基础 1.1.安装 //安装 npm install mockjs --save 1.2.使用 // 使用 Mock var Mock = require('mockjs') Mock.mock( ...
- WINDOWS SERVER 2008 R2安装指南
说明:适用于以下几种操作系统: 1.Windows Server 2008 Standard Endition R2 2.Windows Server 2008 Enterprise Endition ...
- freespace_evidence
根据视点计算点云的freespace_evidence 参考资料: Bresenham's line algorithm:https://en.wikipedia.org/wiki/Bresenham ...
- javascript封装animate动画
面向对象式: Element.prototype.animate=animate; Element.prototype.getStyle=getStyle; function animate(json ...
- sklearn_线性回归
1. 普通线性回归 Linear Regression (1)目标: class sklearn.linear_model.LinearRegression (fit_intercept=True, n ...