diff --git a/1_7.http_proxy_server/curl-test/part1 b/1_7.http_proxy_server/curl-test/part1 new file mode 100644 index 0000000..feb0eb8 Binary files /dev/null and b/1_7.http_proxy_server/curl-test/part1 differ diff --git a/1_7.http_proxy_server/python/testCode/cache/backup b/1_7.http_proxy_server/python/testCode/cache/backup new file mode 100644 index 0000000..e0fd615 --- /dev/null +++ b/1_7.http_proxy_server/python/testCode/cache/backup @@ -0,0 +1,7438 @@ + + + + + + + + + 新浪首页 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+ + + +
+
+ + + +
+
+
+ +
+
+ +
+
+ +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +跳过导航栏 + + + + + + + + + + + + + + +
+ + +
+ + + +
+ + + + + +
+ + +
+ + + +
+ + + + + +
+ + +
+
+ +
+
+ + +
+
+ + + + + +
+
+ +
+ + + +
+ + + +
+
+ 教育 + + 热卖 + + 练字 + + 淘宝 +
+
+ + + + +
+ + +
+ + + + + + + + + + +
+
+ + + +
+
+ +
+
+
+
+ 视频 + 综艺 + 秒拍 +
+ + +
+ +换一换 + + +万能插座有隐患 + + +
+
+ + +
+ +
+ +
+ +
+ + + +
+
+ +
+ +
+
+
+ + 猜你喜欢 + + + + + + + + 热门话题 + +
+ +
+
+
+
+

+
+
+ + + +
+
+

+
+
+ +
+ + + +
+ + + + +
+ + + +
+ + +
+
+ +
+
+
+ + 新闻 + + + +图片 +专栏 + + + + +
+ +2015.6.17 + +
+
+
+ + + + + +
+ + + + + + + +
+ + +
+ +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + +
+ +
+ + + + + +
+ +
+
+ +
+
+ +
+
+ + + +
+ +
+
+ +
+
+ +
+ +
+高清美图   + +
+ +
+
+
+ +
+
+ +
+
+
+
+
+ 汽车 + 购车 + 图赏 +
+ + + + + + + + +
+
+ + +
+
    +
  •  
  • + +
  • + + +
  • +
+
+ + + +
+
+
+
+ 1 + + 2 + + 3 + + 4 +
+
+ + + + +
+
+
+ +
+
+ + +
+ +
+
+
+
+ +
+
+ +
+ + + + +
+ +
+ + + + + +
+ + + +
+ + + +
+ +
+ + +
+ +
+ +
+
+
+ + +
    + +
+ +
    +
  • +
+ + + + +
+
+
+ + + +
+ +
+ +
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+
+
+
+ 财经 + 股票 + 理财 +
+ + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+ +
+ + +
+
+

+ 我爱看图 + 猜你喜欢 + +

+ +
+
+ +
+ + + +
+ + +
+ +
+
+ +
+
+
+
+ 博客 + 精选 + 微博 +
+ + + + + + +
    +
  • +
+ +
+
+
+ + +
+ + + + +
+ + + + + +
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+ +
+ + + + + +
+ + + + + + + +
+ + + +
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+
+ +
+ + + + + + + +
+
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+
+
+ + + +
+ +
+
+ +
+ + + + + + +
+
+
+ +
+
+ + +
+ + +
+
+ + + + + +
+ +
+ + + + + +
+ +
+
+ +
+
+ +
+
+ + +
+ +
+
+ +
+
+
+
+ +
+ +
+ +
+ +
+ + + + + + + +
+ + + + +
+ + + +
+ +
+
+
+
+ 社会 + 公益 +
+
    +
  • +
+ + + + +
+
+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+ + +
+
+ +
+ +
+ + + + +
+
+ +
+
+ +
+
+ + +
+ + + + + +
+ +
+
+ +
+
+ +
+ +
+
+
+ 资讯 +
+ +
    +
  • +
  • 爱问
  • +
+ + + + +
+
+
+ +
+ +
+ + + + + + + +
+ + + +
    +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
+ +
+
+ +
    +
  • + + +
  • +
+ +
+ +
+
+
+ +
+
+ +
+ +
+ + + + + +
+ + + + +
+
+ + + + + + + +
+
+ +
+
+ +
+
+ + + +
+ +
+
+ +
+
+
+
+ + +
+
+ + +
+
+ +
+ +
+ + + +
+ + + + +
+ +
+
+
+ + +
+
+ +
+ + +
+
+ + + +
+ +
+ + + + + +
+ +
+
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+ +
+ + + + + +
+ + + +
+ +
+ +
+
+ +
+ + +
+ +
+ + + +
+
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+
+ +
+ + +
+
+ + + + + +
+
+ +
+
+ +
+ + +
+ +
+ +
+
+
+ +
+ +
+ +
+ + +
+ + + +
+ + +
+ +
+
+

+ 美图 + GIF +

+
+
+
+ +
+
+
+ +
+ + +
+ +
+ +
+ +
+
+ + + + + +
+ + +
+ + +
+ + +
+ + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/1_7.http_proxy_server/python/testCode/cache/www.sina.com.cn b/1_7.http_proxy_server/python/testCode/cache/www.sina.com.cn new file mode 100644 index 0000000..af604da --- /dev/null +++ b/1_7.http_proxy_server/python/testCode/cache/www.sina.com.cn @@ -0,0 +1,7438 @@ + + + + + + + + + 新浪首页 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+ + + +
+
+ + + +
+
+
+ +
+
+ +
+
+ +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +跳过导航栏 + + + + + + + + + + + + + + +
+ + +
+ + + +
+ + + + + +
+ + +
+ + + +
+ + + + + +
+ + +
+
+ +
+
+ + +
+
+ + + + + +
+
+ +
+ + + +
+ + + +
+
+ 教育 + + 热卖 + + 练字 + + 淘宝 +
+
+ + + + +
+ + +
+ + + + + + + + + + +
+
+ + + +
+
+ +
+
+
+
+ 视频 + 综艺 + 秒拍 +
+ + +
+ +换一换 + + +万能插座有隐患 + + +
+
+ + +
+ +
+ +
+ +
+ + + +
+
+ +
+ +
+
+
+ + 猜你喜欢 + + + + + + + + 热门话题 + +
+ +
+
+
+
+

+
+
+ + + +
+
+

+
+
+ +
+ + + +
+ + + + +
+ + + +
+ + +
+
+ +
+
+
+ + 新闻 + + + +图片 +专栏 + + + + +
+ +2015.6.17 + +
+
+
+ + + + + +
+ + + + + + + +
+ + +
+ +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + +
+ +
+ + + + + +
+ +
+
+ +
+
+ +
+
+ + + +
+ +
+
+ +
+
+ +
+ +
+高清美图   + +
+ +
+
+
+ +
+
+ +
+
+
+
+
+ 汽车 + 购车 + 图赏 +
+ + + + + + + + +
+
+ + +
+
    +
  •  
  • + +
  • + + +
  • +
+
+ + + +
+
+
+
+ 1 + + 2 + + 3 + + 4 +
+
+ + + + +
+
+
+ +
+
+ + +
+ +
+
+
+
+ +
+
+ +
+ + + + +
+ +
+ + + + + +
+ + + +
+ + + +
+ +
+ + +
+ +
+ +
+
+
+ + +
    + +
+ +
    +
  • +
+ + + + +
+
+
+ + + +
+ +
+ +
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+
+
+
+ 财经 + 股票 + 理财 +
+ + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+ +
+ + +
+
+

+ 我爱看图 + 猜你喜欢 + +

+ +
+
+ +
+ + + +
+ + +
+ +
+
+ +
+
+
+
+ 博客 + 精选 + 微博 +
+ + + + + + +
    +
  • +
+ +
+
+
+ + +
+ + + + +
+ + + + + +
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+ +
+ + + + + +
+ + + + + + + +
+ + + +
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+
+ +
+ + + + + + + +
+
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+
+
+ + + +
+ +
+
+ +
+ + + + + + +
+
+
+ +
+
+ + +
+ + +
+
+ + + + + +
+ +
+ + + + + +
+ +
+
+ +
+
+ +
+
+ + +
+ +
+
+ +
+
+
+
+ +
+ +
+ +
+ +
+ + + + + + + +
+ + + + +
+ + + +
+ +
+
+
+
+ 社会 + 公益 +
+
    +
  • +
+ + + + +
+
+ + +
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+ + +
+
+ +
+ +
+ + + + +
+
+ +
+
+ +
+
+ + +
+ + + + + +
+ +
+
+ +
+
+ +
+ +
+
+
+ 资讯 +
+ +
    +
  • +
  • 爱问
  • +
+ + + + +
+
+
+ +
+ +
+ + + + + + + +
+ + + +
    +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
+ +
+
+ +
    +
  • + + +
  • +
+ +
+ +
+
+
+ +
+
+ +
+ +
+ + + + + +
+ + + + +
+
+ + + + + + + +
+
+ +
+
+ +
+
+ + + +
+ +
+
+ +
+
+
+
+ + +
+
+ + +
+
+ +
+ +
+ + + +
+ + + + +
+ +
+
+
+ + +
+
+ +
+ + +
+
+ + + +
+ +
+ + + + + +
+ +
+
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+ +
+ + + + + +
+ + + +
+ +
+ +
+
+ +
+ + +
+ +
+ + + +
+
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+
+ +
+ + +
+
+ + + + + +
+
+ +
+
+ +
+ + +
+ +
+ +
+
+
+ +
+ +
+ +
+ + +
+ + + +
+ + +
+ +
+
+

+ 美图 + GIF +

+
+
+
+ +
+
+
+ +
+ + +
+ +
+ +
+ +
+
+ + + + + +
+ + +
+ + +
+ + +
+ + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/1_7.http_proxy_server/python/testCode/cacheUtil.py b/1_7.http_proxy_server/python/testCode/cacheUtil.py new file mode 100644 index 0000000..f7fc14a --- /dev/null +++ b/1_7.http_proxy_server/python/testCode/cacheUtil.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# coding=utf-8 +import urllib +import urllib2 +class CacheUtils: + + def cbk(a, b, c): + '''''鍥炶皟鍑芥暟 + @a: 宸茬粡涓嬭浇鐨勬暟鎹潡 + @b: 鏁版嵁鍧楃殑澶у皬 + @c: 杩滅▼鏂囦欢鐨勫ぇ灏 + ''' + per = 100.0 * a * b / c + if per > 100: + per = 100 + print '%.2f%%' % per + + def download(self, url, local): + urllib.urlretrieve(url, local, cbk) + + def cache(self, url): + fileName = url.split('/')[-1] + req = urllib2.Request(url) + #req.add_header('Range', 'bytes=0-7000') + response = urllib2.urlopen(req) + buffer = response.read() + with open("./cache/img.png", "a+") as fp: + fp.write(buffer) + + diff --git a/1_7.http_proxy_server/python/testCode/py.txt b/1_7.http_proxy_server/python/testCode/py.txt new file mode 100644 index 0000000..d62d43a --- /dev/null +++ b/1_7.http_proxy_server/python/testCode/py.txt @@ -0,0 +1,10 @@ +test1test2test3test4test5test6test7test8test9test1 +test2 +test3 +test4 +test5 +test6 +test7 +test8 +test9 +test1test2test3test4test5test6test7test8test9 \ No newline at end of file diff --git a/1_7.http_proxy_server/python/testCode/res.png b/1_7.http_proxy_server/python/testCode/res.png new file mode 100644 index 0000000..fc4efba Binary files /dev/null and b/1_7.http_proxy_server/python/testCode/res.png differ diff --git a/1_7.http_proxy_server/python/testCode/test.html b/1_7.http_proxy_server/python/testCode/test.html new file mode 100644 index 0000000..64166dd --- /dev/null +++ b/1_7.http_proxy_server/python/testCode/test.html @@ -0,0 +1,23 @@ +鐧惧害涓涓嬶紝浣犲氨鐭ラ亾 +
+ diff --git a/1_7.http_proxy_server/python/testCode/test1.png b/1_7.http_proxy_server/python/testCode/test1.png new file mode 100644 index 0000000..6163778 Binary files /dev/null and b/1_7.http_proxy_server/python/testCode/test1.png differ diff --git a/1_7.http_proxy_server/python/testCode/test2.png b/1_7.http_proxy_server/python/testCode/test2.png new file mode 100644 index 0000000..f063430 Binary files /dev/null and b/1_7.http_proxy_server/python/testCode/test2.png differ diff --git a/1_7.http_proxy_server/python/testCode/testFileIO.py b/1_7.http_proxy_server/python/testCode/testFileIO.py new file mode 100644 index 0000000..f5a4304 --- /dev/null +++ b/1_7.http_proxy_server/python/testCode/testFileIO.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# coding=utf-8 +""" +#fileIO read & print +with open("py.txt") as fp: + #data = fp.read() + data = fp.readline() + print(data) +""" + + +""" +#fileIO foreach write +with open("py.txt", 'a+') as fp: + for num in range(1,10): + #fp.write("test" + str(num) + "\n" ) + fp.writelines("test" + str(num)) +""" + + +with open("py.txt", 'a+') as fp: + for line in fp.readlines(): + line = line.strip() #鍘婚櫎棣栧熬绌虹櫧 + print(line) diff --git a/1_7.http_proxy_server/python/testCode/testUrllib.py b/1_7.http_proxy_server/python/testCode/testUrllib.py new file mode 100644 index 0000000..bdecb6e --- /dev/null +++ b/1_7.http_proxy_server/python/testCode/testUrllib.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# coding=utf-8 +import urllib +import urllib2 +import os +def cbk(a, b, c): + '''''鍥炶皟鍑芥暟 + @a: 宸茬粡涓嬭浇鐨勬暟鎹潡 + @b: 鏁版嵁鍧楃殑澶у皬 + @c: 杩滅▼鏂囦欢鐨勫ぇ灏 + ''' + per = 100.0 * a * b / c + if per > 100: + per = 100 + print '%.2f%%' % per + +""" urllib涓嬭浇 +url = 'http://www.sina.com.cn' +#local = '/home/rh/my_code/OpenWrt_Luci_Lua/1_7.http_proxy_server/python/testCode/sina.html' +#local = '/home/rh/my_code/OpenWrt_Luci_Lua/1_7.http_proxy_server/python/testCode/test.html' +#local = './cache/backup' + +fileName = url.split('/')[-1] +local = os.path.join('./cache',fileName) + +urllib.urlretrieve(url, local, cbk) + +""" + +#url = "http://download.meizu.com/Firmware/Flyme/m1_note/4.2/cmcc/20150507154711/61746475/update.zip" +url = "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superplus/img/logo_white_ee663702.png" +req = urllib2.Request(url) +req.add_header('Range', 'bytes=0-7000') +response = urllib2.urlopen(req) +buffer = response.read() +with open("./cache/test1.png", "a+") as fp: + fp.write(buffer) + + +req = urllib2.Request(url) +req.add_header('Range', 'bytes=7001-14175') +response = urllib2.urlopen(req) +buffer = response.read() +with open("./cache/test2.png", "a+") as fp: + fp.write(buffer) + + + + + + + +""" urllib2涓嬭浇 request澶辫触 +url = 'http://www.sina.com.cn' +req = urllib2.Request(url) +#req.add_header('range','byte:1-100') +response = urllib2.urlopen(req) +file = response.read() + +with open("urllib2test.html", "a+") as fp: + fp.write(file) +""" +"""urlopener 澶辫触""" +url = 'http://www.sina.com.cn' +opener = urllib2.build_opener() +#涓嶅姞澶翠俊鎭垯鍑虹幇403閿欒鍜屼贡鐮 +opener.addheaders = [('User-agent', 'Mozilla/5.0')]; +#opener.addheaders = [('range', 'byte:1-100')] +htmlAll = opener.open( url ).read() +reg1Floor = '
(.*?)
' +#鏂囦欢淇濆瓨缂栫爜鍜屾枃浠剁紪杈戠紪鐮侀兘鏄痷tf-8锛屾墍浠ecode涓娆★紝涓嶇劧浼氬嚭鐜颁贡鐮侊紝浣嗘槸涓嶅奖鍝嶇粨鏋溿 +#htmlAll.decode('utf-8') +print(htmlAll) + + diff --git a/1_7.http_proxy_server/python/testCode/url2.py b/1_7.http_proxy_server/python/testCode/url2.py new file mode 100644 index 0000000..031609f --- /dev/null +++ b/1_7.http_proxy_server/python/testCode/url2.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# coding=utf-8 +import urllib2 +#url = "http://download.meizu.com/Firmware/Flyme/m1_note/4.2/cmcc/20150507154711/61746475/update.zip" +url = "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superplus/img/logo_white_ee663702.png" + +#url = "http://www.sina.com.cn" +req = urllib2.Request(url) +req.add_header('Range', 'bytes=7001-14000') +response = urllib2.urlopen(req) +#print(response.info()) + +html = response.read() +with open("test4.png", "a+") as fp: + fp.write(html) +#print html