1 #捕获异常 2 import urllib.request 3 import urllib.error 4 5 try: 6 response = urllib.request.urlopen('http://sasd.com') 7 except urllib.error.URLError a... ...
分类:
Web程序 时间:
2017-05-11 19:45:33
阅读次数:
170
urllib.request.urlopen(url,data,timeout) 其中如果data被赋值,则请求的方式就会由get转为post,而post需要提供一些待处理的数据。 这些待处理的数据需要一定的格式,因此就需要urllib.parse.urlencode urllib.parse.ur ...
分类:
Web程序 时间:
2017-05-11 12:23:20
阅读次数:
240
import re from urllib import request from lxml import etree testurl="http://news.163.com/rank/" with request.urlopen(testurl) as f: print('Status:', f ...
分类:
编程语言 时间:
2017-05-09 20:38:23
阅读次数:
232
一、下载一只猫 urlopen()中的url可以是string,也可以是request object,因此可以是: response.geturl()得到url地址 response.info()得到HTTPMessage对象,可以通过print()得到head信息 response.getcode ...
分类:
编程语言 时间:
2017-05-09 13:42:18
阅读次数:
239
上边是读取结果为列表形式,下边用dictReader()读取城字典形式 ...
分类:
其他好文 时间:
2017-05-08 21:59:29
阅读次数:
220
1 lines (8 sloc) 333 Bytes 2 from urllib.request import urlopen 3 from bs4 import BeautifulSoup 4 5 html = urlopen("http://en.wikipedia.org/wiki/Pytho... ...
分类:
其他好文 时间:
2017-05-08 21:51:21
阅读次数:
137
转载请注明作者和出处:http://blog.csdn.net/c406495762
运行平台: Windows
Python版本: Python3.x
IDE: Sublime text3一、...
分类:
编程语言 时间:
2017-05-07 17:36:47
阅读次数:
4283
1 定义一个方法get_page(url),url参数是需要获取网页内容的网址,返回网页的内容。提示(可以了解python的urllib模块) 2 import urllib.request 3 4 def get_page(url): 5 response = urllib.request.url... ...
分类:
编程语言 时间:
2017-05-02 23:46:33
阅读次数:
376
1 from urllib.request import Request, urlopen 2 from urllib.error import URLError, HTTPError 3 req = Request(someurl) 4 try: 5 response = urlopen(req)... ...
分类:
其他好文 时间:
2017-04-23 15:53:17
阅读次数:
151
1、urlopen()方法 urllib.request.urlopen(url[,data[,proxies]]) 创建一个表示远程url的类文件对象,然后像本地文件一样的操作这个类文件对象来获取远程数据 参数url表示远程数据的路径,一般是指网址 参数data表示以post方式提交到url的数据 ...
分类:
Web程序 时间:
2017-04-22 20:37:58
阅读次数:
234