urllib

以下是为您整理出来关于【urllib】合集内容,如果觉得还不错,请帮忙转发推荐。

【urllib】技术教程文章

Python网络编程中urllib2模块的用法总结【图】

一、最基础的应用import urllib2url = rhttp://www.baidu.com html = urllib2.urlopen(url).read()print html客户端与服务器端通过request与response来沟通,客户端先向服务端发送request,然后接收服务端返回的response urllib2提供了request的类,可以让用户在发送请求前先构造一个request的对象,然后通过urllib2.urlopen方法来发送请求import urllib2url = rhttp://www.baidu.com req = urllib2.Request(url) html = urllib2.u...

Pythonurllib模块urlopen()与urlretrieve()详解

1.urlopen()方法urllib.urlopen(url[, data[, proxies]]) :创建一个表示远程url的类文件对象,然后像本地文件一样操作这个类文件对象来获取远程数据。参数url表示远程数据的路径,一般是网址;参数data表示以post方式提交到url的数据(玩过web的人应该知道提交数据的两种方式:post与get。如果你不清楚,也不必太在意,一般情况下很少用到这个参数);参数proxies用于设置代理。urlopen返回 一个类文件对象,它提供了如下方法:read(...

python使用urllib2模块获取gravatar头像实例

Gravatar注册地址: https://en.gravatar.com/代码如下:"""`Gravatar <https://en.gravatar.com/site/implement/>`_""" # import code for encoding urls and generating md5 hashesimport urllib2, hashlib # Make response slow if verify whether default avatar or not.# So let js do it, see `/static/js/article.js`.def gravatar_url(email, size=40, verify_default=False): """Construct the gravatar url.""" grav...

python33urllib2使用方法细节讲解

Proxy 的设置 urllib2 默认会使用环境变量 http_proxy 来设置 HTTP Proxy。如果想在程序中明确控制 Proxy 而不受环境变量的影响,可以使用下面的方式代码如下:import urllib2 enable_proxy = Trueproxy_handler = urllib2.ProxyHandler({"http" : http://some-proxy.com:8080})null_proxy_handler = urllib2.ProxyHandler({}) if enable_proxy: opener = urllib2.build_opener(proxy_handler)else: opener = urllib2.build_o...

python3使用urllib示例取googletranslate(谷歌翻译)

代码如下:#!/usr/bin/env python3# -*- coding: utf-8 -*-# File Name : gt1.py# Purpose :# Creation Date : 1390366260# Last Modified : Wed 22 Jan 2014 06:14:11 PM CST# Release By : Doom.zhou import urllib.requestimport sys typ = sys.getfilesystemencoding() def translate(querystr, to_l="zh", from_l="en"): for google tranlate by doom C_agent = {User-Agent: "Mozilla/5.0 (X11; Linux x86_64) Appl...

python使用urllib模块和pyquery实现阿里巴巴排名查询

urllib基础模块的应用,通过该类获取到url中的html文档信息,内部可以重写代理的获取方法代码如下:class ProxyScrapy(object): def __init__(self): self.proxy_robot = ProxyRobot() self.current_proxy = None self.cookie = cookielib.CookieJar() def __builder_proxy_cookie_opener(self): cookie_handler = urllib2.HTTPCookieProcessor(self.cookie) handlers = ...

python的urllib模块显示下载进度示例

代码如下: def report_hook(count, block_size, total_size):... print %02d%%%(100.0 * count * block_size/ total_size)... urllib.urlretrieve("http://sports.sina.com.cn/", reporthook= report_hook)00%01%03%...

urllib2自定义opener详解

urllib2.urlopen()函数不支持验证、cookie或者其它HTTP高级功能。要支持这些功能,必须使用build_opener()函数创建自定义Opener对象。代码如下:build_opener([handler1 [ handler2, ... ]]) 参数handler是Handler实例,常用的有HTTPBasicAuthHandler、HTTPCookieProcessor、ProxyHandler等。 build_opener ()返回的对象具有open()方法,与urlopen()函数的功能相同。 如果要修改http报头,可以用:代码如下:import urllib2opener = ...

python网页请求urllib2模块简单封装代码

对python网页请求模块urllib2进行简单的封装。 例子:代码如下:#!/usr/bin/python#coding: utf-8import base64import urllibimport urllib2import time class SendRequest: This class use to set and request the http, and get the info of response. e.g. set Authorization Type, request tyep.. e.g. get html content, state code, cookie.. SendRequest(http://10.75.0.103:8850/2/photos/square/type.json, ...

python通过urllib2获取带有中文参数url内容的方法

本文实例讲述了python通过urllib2获取带有中文参数url内容的方法。分享给大家供大家参考。具体如下: 对于中文的参数如果不进行编码的话,python的urllib2直接处理会报错,我们可以先将中文转换成utf-8编码,然后使用urllib2.quote方法对参数进行url编码后传递。content = u你好 jb51.net content = content.encode(utf-8) content = urllib2.quote(content) api_url = http://www.gxlcms.com/q=%s%content res = urllib2.urlopen(...

URLLIB - 相关标签