环境:Python2.7.9 / Sublime Text 2 / Chrome1.url访问,直接调用urllib库函数即可import urllib2url='http://www.baidu.com/'response = urllib2.urlopen(url)html=response.r...
分类:
编程语言 时间:
2015-02-14 12:16:42
阅读次数:
5893
最先想试试python的爬虫功能,于是用easy_install安装了beautifulsoup,下面是我写的demo代码,可以简单看看
#coding=utf-8
import urllib2
from BeautifulSoup import BeautifulSoup as bs
url_addr = 'http://car.autohome.com.cn/baoyang/detail...
分类:
编程语言 时间:
2015-02-12 18:28:39
阅读次数:
208
# -*- coding:utf8 -*-from bs4 import BeautifulSoupimport os, sys, urllib2, urllibfrom multiprocessing.dummy import Pool as ThreadPoolurls = []def down...
分类:
编程语言 时间:
2015-02-09 20:14:15
阅读次数:
231
python自带的urllib,urllib2可以极方便做http操作,在我们按照http方式提交消息请求后,有可能会看见返回这个错误“403 forbidden",这是请求的网站做了阻止,于是我们需要把自己伪装成模拟器。对此,可以加上headers={'User-Agent':user-ag...
分类:
编程语言 时间:
2015-02-09 15:28:43
阅读次数:
559
在自动化脚本中,文件下载是比较常见的操作,一般情况下,我们会将文件放到某个http服务器上,这时,当脚本中需要这个文件时,就需要使用到http下载的功能了
最基本的下载功能实现
实现最基本的功能,传入文件下载路径和文件本地保存路径,下载到本地
def DownloadFile(url,savePath):
"""
| ##@函数目的: 下载文件
| ##@参数说明:u...
分类:
编程语言 时间:
2015-02-09 12:57:07
阅读次数:
205
#coding:utf-8import urllib, urllib2, cookielibimport os, timeimport redef login (): user = 'user' cookiename = 'chd%s.coockie' % ( user ) logined = Fa...
分类:
其他好文 时间:
2015-02-06 18:36:59
阅读次数:
261
# -*- coding:utf8 -*-from bs4 import BeautifulSoupimport os, sys, urllib2, urllibimport thread, threadingclass downloader(threading.Thread): """docstr...
分类:
编程语言 时间:
2015-02-06 18:11:00
阅读次数:
201
#coding:utf8#Author = yyobin@gmail.com#Create = 20120517import cookielib, urllib2, urllibimport os, sys,socket ,re#解析有多少页博客pageStr = """allCount : '(\...
分类:
其他好文 时间:
2015-02-06 16:40:30
阅读次数:
290
网上关于使用python 的发送multipart/form-data的方法,多半是采用
ulrlib2 的模拟post方法,如下:
import urllib2
boundary='-------------------------7df3069603d6'
data=[]
data.append('--%s' % boundary)
data.append('Content-Dispos...
分类:
编程语言 时间:
2015-02-06 11:23:31
阅读次数:
177
import urllib2,cookielibclass HTTPRefererProcessor(urllib2.BaseHandler): def __init__(self): self.referer = None def http_request(self, request): if (...
分类:
编程语言 时间:
2015-02-03 12:54:17
阅读次数:
162