From d3449c9135f9bdce8d3dae28e42f50a7cd5fdf5a Mon Sep 17 00:00:00 2001 From: mzcyx <920082975@qq.com> Date: Sat, 24 Dec 2016 15:09:50 +0800 Subject: [PATCH 1/9] Update hostloc.py --- hostloc/hostloc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hostloc/hostloc.py b/hostloc/hostloc.py index 971b865..177f820 100644 --- a/hostloc/hostloc.py +++ b/hostloc/hostloc.py @@ -35,8 +35,9 @@ def __init__(self,username,passwd): login_data['password']=passwd self.session=requests.Session() self.session.headers=headers - self.pass_jdkey() self.login() + self.pass_jdkey() + def pass_jdkey(self): html=self.session.get(index).content From 6e1555b47e6e13f2049d6f143603e11183394877 Mon Sep 17 00:00:00 2001 From: mzcyx <920082975@qq.com> Date: Mon, 26 Dec 2016 14:14:49 +0800 Subject: [PATCH 2/9] update --- ASCII-ART/picture_to_pixles.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/ASCII-ART/picture_to_pixles.py b/ASCII-ART/picture_to_pixles.py index bad19c2..ce4902e 100644 --- a/ASCII-ART/picture_to_pixles.py +++ b/ASCII-ART/picture_to_pixles.py @@ -1,14 +1,19 @@ # -*- coding=utf-8 -*- from PIL import Image +import sys +import requests +import StringIO -ASCII_CHARS = ['#', '@', '$', '&', 'S', '+', '=', ';', ':', '.', ' '] + +ASCII_CHARS = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft|()1{}[]?-_+~i!lI;:,^ " max_width=100 #调节此项可调节图片大小,越大图片信息越好。 +range_width=float(255)/(len(ASCII_CHARS)-1) def scale_image(image, new_width=max_width): """Resizes an image preserving the aspect ratio. """ (original_width, original_height) = image.size - aspect_ratio = original_height/float(original_width) + aspect_ratio = original_height/float(original_width)*0.5 new_height = int(aspect_ratio * new_width) new_image = image.resize((new_width, new_height)) return new_image @@ -16,14 +21,13 @@ def scale_image(image, new_width=max_width): def convert_to_grayscale(image): return image.convert('L') -def map_pixels_to_ascii_chars(image, range_width=25): +def map_pixels_to_ascii_chars(image, range_width=range_width): """Maps each pixel to an ascii char based on the range in which it lies. 0-255 is divided into 11 ranges of 25 pixels each. """ pixels_in_image = list(image.getdata()) - pixels_to_chars = [ASCII_CHARS[pixel_value/range_width] for pixel_value in - pixels_in_image] + pixels_to_chars = [ASCII_CHARS[int(pixel_value/range_width)] for pixel_value in pixels_in_image] return "".join(pixels_to_chars) def convert_image_to_ascii(image, new_width=max_width): @@ -39,8 +43,15 @@ def convert_image_to_ascii(image, new_width=max_width): def handle_image_conversion(image_filepath): image = None + session=requests.Session() + session.headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'} try: - image = Image.open(image_filepath) + if image_filepath.startswith('http://') or image_filepath.startswith('https://'): + resp=session.get(image_filepath) + imagebuf=StringIO.StringIO(resp.content) + image=Image.open(imagebuf) + else: + image = Image.open(image_filepath) except Exception, e: print "Unable to open image file {image_filepath}.".format(image_filepath=image_filepath) print e @@ -49,7 +60,10 @@ def handle_image_conversion(image_filepath): print image_ascii if __name__=='__main__': - image_file_path = 'xzz.jpg' - handle_image_conversion(image_file_path) - - + while 1: + print u"请输入图片地址:" + try: + image_file_path = sys.argv[1] + except: + image_file_path=raw_input() + handle_image_conversion(image_file_path) From dd71b3a7dd627a0276a732a9f0f66f5535ca2d84 Mon Sep 17 00:00:00 2001 From: mzcyx <920082975@qq.com> Date: Fri, 13 Jan 2017 11:43:30 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BE=E5=BA=A6?= =?UTF-8?q?=E5=9B=BE=E5=BA=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + baidu/README.md | 12 ++++++ baidu/baidu.ico | Bin 0 -> 9086 bytes baidu/baidu.py | 88 +++++++++++++++++++++++++++++++++++++++++ baidu/baidu_ui.ui | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 199 insertions(+) create mode 100644 baidu/README.md create mode 100644 baidu/baidu.ico create mode 100644 baidu/baidu.py create mode 100644 baidu/baidu_ui.ui diff --git a/README.md b/README.md index e8dbad1..490e98b 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ 4. v2ex:v2ex签到脚本 5. fuliba:福利吧签到脚本 6. ASCII-ART:图片转字符画 +7. baidu:百度图床~~ > 注: diff --git a/baidu/README.md b/baidu/README.md new file mode 100644 index 0000000..25b5761 --- /dev/null +++ b/baidu/README.md @@ -0,0 +1,12 @@ +# 用法 + +首先安装用的库: + +`pip install QT.py` + +`pip install requests` + +然后用法查看gif: + +![](https://ooo.0o0.ooo/2017/01/13/5878494a9468b.gif) + diff --git a/baidu/baidu.ico b/baidu/baidu.ico new file mode 100644 index 0000000000000000000000000000000000000000..5e0d125a778391eb70d74e37dfcc5b93cb70d080 GIT binary patch literal 9086 zcmeI0Ylu}<6vxj^YsS$EOT#D~!m&uYwdOR z*=L`9ZWI;xH}1lSzayhLqoU}vD2mR5anKHGmz2(mqUMLYDL3@}>6?LkXW)3kHA55h zOBq`BrvR%oVior=lyU*`l)(g>0WZK>_y9J*8?X|V!R>H0jE2);h|y=GuYm=y3O2)c z@FVfq&`y1Ac~W@D*$a<#iY;`P#mH*e!&#_YapI(f#`b zY|P%!2N-W^PX_4=kMwfBc22bR2BuFp8iCI@4a#{Bzc8nxHnoB9ajPRo$< zk_P2#=Vob!oaZ+<=VFGO?`>et+E;JMknu6to=HtXm8Vc z%u^;4>@&!kSDfGP#GDPaoQrUem2>EM7vjcG+paa&4z9FNIl*nnp*)NjuR_}Ve0$}4 zhsj4Vb-rE!C3qX|gDhtb+=8NSjau^l3;($$aw~d0_}8TRR=5bN6+I6++l@Eqo5~gK zM{#3?#wlAbt)302T)l zmtUga-dDxZ9<><$1mD)JZ=wGZaAgdYz2MsUWu2vOa-F=g?$yWO`?+;}qiQTybPal6 zehpf$uDzbOH$gvZ`O-$iPvF}7<)oaoUbTLFKew(Nu7!{cr?DNLhgaZ9xB*UtkZ2ty zJr7zN*N2=<+ok9O;O6L;JL#Wc>?^5i&SiRc=ywQz47aY|8%9E$TtJ8Rde_G8*1$tx&z*X&>KR@R@4>S$9R@-*ay~{oA(ZbP z+OIT0n$fy%`#^hzo|TUvbPsN%UA}(I4YZ8`E4sEOTS=*BVejujdcJRU;w+?m6#P6s zr)`8|r@2&{Z)fZ4=&R=bJ0XL`<7m}Ae+*s&&8OzyN-G7OU+lQPUSti?*Mas&-^SKE z>6-(2itd*$chg|U4Cznl*ZWB_7eY2}+lSaxyLJ^bi#&ysJEmXO+HEs|=Ox(6cQ1@J z_VrL&H><$U)2-|K?g}%w_7pv%ZogkXNdH7*UoW*XAqRcq+4In7%Aq~O&0F&ao{GNeb zsZbo$t?^J@+iF?kIH~)`!5-bw9rt9ku0vYaFWrTERT{@u+3znDCrft}O3S1>n~t4l HGvEIKcTeLG literal 0 HcmV?d00001 diff --git a/baidu/baidu.py b/baidu/baidu.py new file mode 100644 index 0000000..29c9598 --- /dev/null +++ b/baidu/baidu.py @@ -0,0 +1,88 @@ +# -*- coding=utf8 -*- +import sys +reload(sys) +sys.setdefaultencoding('utf-8') +from PyQt4 import QtCore, QtGui, uic +import requests +import re + +tc_api='http://image.baidu.com/pictureup/uploadshitu' +files={ + 'image':'' + } +data={'pos':'upload' + ,'uptype':'upload_pc' + ,'fm':'index'} + +def upload_file(filepath): + try: + img=open(filepath,'rb') + except Exception,e: + print e + sys.exit(0) + files['image']=img + c=requests.post(tc_api,files=files,data=data) + img_url=re.findall('queryImageUrl=(.*?)&querySign',c.url)[0] + img1=re.sub('%3A',':',img_url) + img2=re.sub('%2F','/',img1) + return img2 + +qtCreatorFile = "baidu_ui.ui" # Enter file here. + +Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) + +class MyApp(QtGui.QMainWindow, Ui_MainWindow): + def __init__(self): + QtGui.QMainWindow.__init__(self) + Ui_MainWindow.__init__(self) + self.setupUi(self) + self.thread=Worker() + self.fileSelect.clicked.connect(self.selectFile) + self.thread.sinOut2.connect(self.show_result) + + def selectFile(self): + filepath=self.to_utf8(QtGui.QFileDialog.getOpenFileName(self,u'选择图片','',r'Image Files(*.png *.jpg *.bmp *.jpeg *.gif)')) + self.thread.getPath((filepath,)) + self.fileSelect.setEnabled(False) + + + def show_result(self,result): + img,isTrue=result[0],result[1] + self.markdown_show.setText('![]('+img+')') + self.realurl.setText(img) + self.fileSelect.setEnabled(isTrue) + + def to_utf8(self,input): + return unicode(input,'utf8','ignore') + + +class Worker(QtCore.QThread): + sinOut2 = QtCore.pyqtSignal(tuple) + + def __init__(self,parent=None): + super(Worker,self).__init__(parent) + + def getPath(self,filepath): + self.filepath=filepath[0] + self.start() + + + def run(self): + try: + img=open(self.filepath,'rb') + except Exception,e: + print e + sys.exit(0) + files['image']=img + c=requests.post(tc_api,files=files,data=data) + img_url=re.findall('queryImageUrl=(.*?)&querySign',c.url)[0] + img1=re.sub('%3A',':',img_url) + img2=re.sub('%2F','/',img1) + self.sinOut2.emit((img2,True)) + + +if __name__ == "__main__": + app = QtGui.QApplication(sys.argv) + window = MyApp() + window.show() + sys.exit(app.exec_()) diff --git a/baidu/baidu_ui.ui b/baidu/baidu_ui.ui new file mode 100644 index 0000000..aa7e9a3 --- /dev/null +++ b/baidu/baidu_ui.ui @@ -0,0 +1,98 @@ + + + Form + + + + 0 + 0 + 395 + 154 + + + + 百度图床 + + + + + 120 + 20 + 251 + 31 + + + + + + + 120 + 60 + 251 + 31 + + + + + + + 30 + 20 + 91 + 21 + + + + + 微软雅黑 + 75 + true + + + + MarkDown + + + Qt::RichText + + + + + + 50 + 60 + 61 + 21 + + + + + 微软雅黑 + 75 + true + + + + 图片链接 + + + Qt::RichText + + + + + + 120 + 110 + 93 + 28 + + + + 选择图片 + + + + + + From 384b20e0a6f60626c56f5c8fa66f58718d65d4f5 Mon Sep 17 00:00:00 2001 From: mzcyx <920082975@qq.com> Date: Fri, 13 Jan 2017 12:58:55 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E8=BF=98=E6=98=AF=E7=94=A8sm.ms=E5=9B=BE?= =?UTF-8?q?=E5=BA=8A=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baidu/README.md | 12 --------- baidu/baidu.ico | Bin 9086 -> 0 bytes baidu/smms.py | 26 ++++++++++++++++++ baidu/smms.pyc | Bin 0 -> 909 bytes baidu/{baidu.py => tuchuang.py} | 37 +++----------------------- baidu/{baidu_ui.ui => tuchuang_ui.ui} | 0 6 files changed, 30 insertions(+), 45 deletions(-) delete mode 100644 baidu/README.md delete mode 100644 baidu/baidu.ico create mode 100644 baidu/smms.py create mode 100644 baidu/smms.pyc rename baidu/{baidu.py => tuchuang.py} (58%) rename baidu/{baidu_ui.ui => tuchuang_ui.ui} (100%) diff --git a/baidu/README.md b/baidu/README.md deleted file mode 100644 index 25b5761..0000000 --- a/baidu/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# 用法 - -首先安装用的库: - -`pip install QT.py` - -`pip install requests` - -然后用法查看gif: - -![](https://ooo.0o0.ooo/2017/01/13/5878494a9468b.gif) - diff --git a/baidu/baidu.ico b/baidu/baidu.ico deleted file mode 100644 index 5e0d125a778391eb70d74e37dfcc5b93cb70d080..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9086 zcmeI0Ylu}<6vxj^YsS$EOT#D~!m&uYwdOR z*=L`9ZWI;xH}1lSzayhLqoU}vD2mR5anKHGmz2(mqUMLYDL3@}>6?LkXW)3kHA55h zOBq`BrvR%oVior=lyU*`l)(g>0WZK>_y9J*8?X|V!R>H0jE2);h|y=GuYm=y3O2)c z@FVfq&`y1Ac~W@D*$a<#iY;`P#mH*e!&#_YapI(f#`b zY|P%!2N-W^PX_4=kMwfBc22bR2BuFp8iCI@4a#{Bzc8nxHnoB9ajPRo$< zk_P2#=Vob!oaZ+<=VFGO?`>et+E;JMknu6to=HtXm8Vc z%u^;4>@&!kSDfGP#GDPaoQrUem2>EM7vjcG+paa&4z9FNIl*nnp*)NjuR_}Ve0$}4 zhsj4Vb-rE!C3qX|gDhtb+=8NSjau^l3;($$aw~d0_}8TRR=5bN6+I6++l@Eqo5~gK zM{#3?#wlAbt)302T)l zmtUga-dDxZ9<><$1mD)JZ=wGZaAgdYz2MsUWu2vOa-F=g?$yWO`?+;}qiQTybPal6 zehpf$uDzbOH$gvZ`O-$iPvF}7<)oaoUbTLFKew(Nu7!{cr?DNLhgaZ9xB*UtkZ2ty zJr7zN*N2=<+ok9O;O6L;JL#Wc>?^5i&SiRc=ywQz47aY|8%9E$TtJ8Rde_G8*1$tx&z*X&>KR@R@4>S$9R@-*ay~{oA(ZbP z+OIT0n$fy%`#^hzo|TUvbPsN%UA}(I4YZ8`E4sEOTS=*BVejujdcJRU;w+?m6#P6s zr)`8|r@2&{Z)fZ4=&R=bJ0XL`<7m}Ae+*s&&8OzyN-G7OU+lQPUSti?*Mas&-^SKE z>6-(2itd*$chg|U4Cznl*ZWB_7eY2}+lSaxyLJ^bi#&ysJEmXO+HEs|=Ox(6cQ1@J z_VrL&H><$U)2-|K?g}%w_7pv%ZogkXNdH7*UoW*XAqRcq+4In7%Aq~O&0F&ao{GNeb zsZbo$t?^J@+iF?kIH~)`!5-bw9rt9ku0vYaFWrTERT{@u+3znDCrft}O3S1>n~t4l HGvEIKcTeLG diff --git a/baidu/smms.py b/baidu/smms.py new file mode 100644 index 0000000..a76a238 --- /dev/null +++ b/baidu/smms.py @@ -0,0 +1,26 @@ +#-*- coding=utf-8 -*- +import requests +import json +import sys + +tc_api='https://sm.ms/api/upload' +files={ + 'smfile':'' + } +data={'ssl':'false' + ,'format':'json'} + +def smms(filepath): + try: + img=open(filepath,'rb') + except Exception,e: + print e + sys.exit(0) + files['smfile']=img + c=requests.post(tc_api,files=files,data=data) + dat=json.loads(c.content) + if dat['code']=='error': + img=dat['msg'] + if dat['code']=='success': + img=dat['data']['url'] + return img \ No newline at end of file diff --git a/baidu/smms.pyc b/baidu/smms.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3002c29f1f966179a3fbaffffa960053eebd94f3 GIT binary patch literal 909 zcmbVJO>fgc5S_K1khqQL2L}pVk#a!It%s;WAV6^H!3YsWLCE!P+D-h0XDuaCaw-RI z{1p!TGkyTP*_3j}_Ks&~XWzVe6aE^+-#)D-8Qnf1{x7h20;BOM%890TzM`r68xLq2 zkcJJ(A{dg6=xiF1MYKb@OK18X=^kR(_30~cx&ruq7z5n?#&f|B;a)pe^LRAk;3pEa+VB6XQUOfu!-D=hvAvpy!k zZG1;J0c{n1ET2;36fI+F#-z3ZsZBs{-?@Mm=p~>VMXFRZ*(gFC^mh&di!M2I75Pwy zTn}l%HYC@lMNFHJ7JG7W8_@=Lx^w~!mH{>2{k}&hs9b``?P1>^{_y(_lH@WR>1YWSXXGyhH_Gfh{Cxv&=C2Sli^oeSs0}s@jyG zPV{D#nc7(>>7`xou+7T4L;%nyNSH4zitdi;ik(;8WuGy!L=qB#^z>wW>`P~WM2(?L z#G}Y0>(pKQLbkZV2#AcgnUA5NAwuL0KZBQzXCK%!JbS4NTUvHa>Z)e;+VIj<_3SdW zx}9-R@M*pFZHYg?MSdheDpbenzUrt$6|2YUNFAsF)}b0oYsrxqVV)d_c_79g_?Dhv f`;X3lauTHTqS9?{p368{D(x%0K^N@eAjbLwMLw}U literal 0 HcmV?d00001 diff --git a/baidu/baidu.py b/baidu/tuchuang.py similarity index 58% rename from baidu/baidu.py rename to baidu/tuchuang.py index 29c9598..328ecec 100644 --- a/baidu/baidu.py +++ b/baidu/tuchuang.py @@ -5,29 +5,9 @@ from PyQt4 import QtCore, QtGui, uic import requests import re +from smms import smms -tc_api='http://image.baidu.com/pictureup/uploadshitu' -files={ - 'image':'' - } -data={'pos':'upload' - ,'uptype':'upload_pc' - ,'fm':'index'} - -def upload_file(filepath): - try: - img=open(filepath,'rb') - except Exception,e: - print e - sys.exit(0) - files['image']=img - c=requests.post(tc_api,files=files,data=data) - img_url=re.findall('queryImageUrl=(.*?)&querySign',c.url)[0] - img1=re.sub('%3A',':',img_url) - img2=re.sub('%2F','/',img1) - return img2 - -qtCreatorFile = "baidu_ui.ui" # Enter file here. +qtCreatorFile = "tuchuang_ui.ui" # Enter file here. Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) @@ -68,17 +48,8 @@ def getPath(self,filepath): def run(self): - try: - img=open(self.filepath,'rb') - except Exception,e: - print e - sys.exit(0) - files['image']=img - c=requests.post(tc_api,files=files,data=data) - img_url=re.findall('queryImageUrl=(.*?)&querySign',c.url)[0] - img1=re.sub('%3A',':',img_url) - img2=re.sub('%2F','/',img1) - self.sinOut2.emit((img2,True)) + img=smms(self.filepath) + self.sinOut2.emit((img,True)) if __name__ == "__main__": diff --git a/baidu/baidu_ui.ui b/baidu/tuchuang_ui.ui similarity index 100% rename from baidu/baidu_ui.ui rename to baidu/tuchuang_ui.ui From 9b1ec2421d4599428c35abc95a81d2f7f5b22221 Mon Sep 17 00:00:00 2001 From: mzcyx <920082975@qq.com> Date: Fri, 13 Jan 2017 13:36:41 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=9B=BE=E5=BA=8A=E6=94=B9=E7=94=A8sm.ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a05e2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,91 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +.venv/ +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject From d810a717ca6e790f5eea0e0b58c57ccf9fded9cd Mon Sep 17 00:00:00 2001 From: mzcyx <920082975@qq.com> Date: Fri, 13 Jan 2017 13:37:39 +0800 Subject: [PATCH 6/9] s --- baidu/smms.pyc | Bin 909 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 baidu/smms.pyc diff --git a/baidu/smms.pyc b/baidu/smms.pyc deleted file mode 100644 index 3002c29f1f966179a3fbaffffa960053eebd94f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 909 zcmbVJO>fgc5S_K1khqQL2L}pVk#a!It%s;WAV6^H!3YsWLCE!P+D-h0XDuaCaw-RI z{1p!TGkyTP*_3j}_Ks&~XWzVe6aE^+-#)D-8Qnf1{x7h20;BOM%890TzM`r68xLq2 zkcJJ(A{dg6=xiF1MYKb@OK18X=^kR(_30~cx&ruq7z5n?#&f|B;a)pe^LRAk;3pEa+VB6XQUOfu!-D=hvAvpy!k zZG1;J0c{n1ET2;36fI+F#-z3ZsZBs{-?@Mm=p~>VMXFRZ*(gFC^mh&di!M2I75Pwy zTn}l%HYC@lMNFHJ7JG7W8_@=Lx^w~!mH{>2{k}&hs9b``?P1>^{_y(_lH@WR>1YWSXXGyhH_Gfh{Cxv&=C2Sli^oeSs0}s@jyG zPV{D#nc7(>>7`xou+7T4L;%nyNSH4zitdi;ik(;8WuGy!L=qB#^z>wW>`P~WM2(?L z#G}Y0>(pKQLbkZV2#AcgnUA5NAwuL0KZBQzXCK%!JbS4NTUvHa>Z)e;+VIj<_3SdW zx}9-R@M*pFZHYg?MSdheDpbenzUrt$6|2YUNFAsF)}b0oYsrxqVV)d_c_79g_?Dhv f`;X3lauTHTqS9?{p368{D(x%0K^N@eAjbLwMLw}U From 8beded6435e41c74f3766f95f9302fcd159d56f9 Mon Sep 17 00:00:00 2001 From: za2016 <920082975@qq.com> Date: Fri, 21 Jul 2017 10:02:18 +0800 Subject: [PATCH 7/9] Update zhihu_picture_downloader.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 获取图片链接无需xsrf了 --- zhihu/zhihu_picture_downloader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zhihu/zhihu_picture_downloader.py b/zhihu/zhihu_picture_downloader.py index 6730ef9..2c1a0a1 100644 --- a/zhihu/zhihu_picture_downloader.py +++ b/zhihu/zhihu_picture_downloader.py @@ -99,7 +99,7 @@ def login(email,passwd): def get_pic_from_topic(id,offset): global session topicurl=topic_url+str(id) - _xsrf=get_xsrf(topicurl) + #_xsrf=get_xsrf(topicurl) pic_re=re.compile('data-actualsrc="(.*?)"') inner_data={"url_token":id ,"pagesize":10 @@ -111,7 +111,7 @@ def get_pic_from_topic(id,offset): session.headers['Referer']=topicurl session.headers['Host']='www.zhihu.com' session.headers['Origin']='https://www.zhihu.com' - session.headers['X-Xsrftoken']=_xsrf + #session.headers['X-Xsrftoken']=_xsrf js_data=session.post(api_url,data=data) dat=json.loads(js_data.content)['msg'] pictures=[] @@ -160,4 +160,4 @@ def downloader(url,path): for pic in pictures: downloader(pic,savepath) print u"=====下载完毕=====" - \ No newline at end of file + From e74365cdf4b1ea6920c4c524a881cecc2e482d34 Mon Sep 17 00:00:00 2001 From: za2016 <920082975@qq.com> Date: Thu, 14 Sep 2017 11:11:16 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AE=9D=E7=99=BB=E5=BD=95=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + alipay/README.md | 11 +++ alipay/alipay.py | 181 ++++++++++++++++++++++++++++++++++++++++++++++ hostloc/README.md | 3 +- 4 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 alipay/README.md create mode 100644 alipay/alipay.py diff --git a/README.md b/README.md index 490e98b..10e9e8c 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ 5. fuliba:福利吧签到脚本 6. ASCII-ART:图片转字符画 7. baidu:百度图床~~ +8. alipay: 支付宝登录&获取订单信息 > 注: diff --git a/alipay/README.md b/alipay/README.md new file mode 100644 index 0000000..604313d --- /dev/null +++ b/alipay/README.md @@ -0,0 +1,11 @@ +# 支付宝登录 & 获取订单信息脚本 + +使用前准备: +1. 安装selenium:`pip install selenium` +2. 下载webdriver。phantomjs无界面,适合linux;chromedriver方便调试。自行百度下载 +3. 修改**USERNMAE**和**PASSWD** + +运行: +`python alipay_login.py` + +pps. 脚本非原创。在v2ex一名v友的基础上修改的 diff --git a/alipay/alipay.py b/alipay/alipay.py new file mode 100644 index 0000000..78b9fa2 --- /dev/null +++ b/alipay/alipay.py @@ -0,0 +1,181 @@ +#-*- coding=utf-8 -*- +""" +支付宝登录获取订单信息脚本 +ps.没啥卵用,使用selenium不稳定,经常出现问题。 +使用前准备: +1.安装selenium:pip install selenium +2.下载webdriver。phantomjs无界面,适合linux;chromedriver方便调试。自定百度 +3.修改USERNMAE和PASSWD + +运行: +python alipay_login.py + +pps. 脚本非原创。在v2ex一名v友的基础上修改的 +""" +import requests +from selenium import webdriver +import time +import pickle +import re +requests.packages.urllib3.disable_warnings() + +# 登录 url +Login_Url = 'https://auth.alipay.com/login/index.htm?goto=https://consumeprod.alipay.com/record/advanced.htm' +# 账单 url +Bill_Url = 'https://consumeprod.alipay.com/record/advanced.htm' +# 登录用户名和密码 +USERNMAE = '' +PASSWD = '' +# 自定义 headers +HEADERS = { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36', + 'Referer': 'https://consumeprod.alipay.com/record/advanced.htm', + 'Host': 'consumeprod.alipay.com', + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', + 'Connection': 'keep-alive' +} + + +class Alipay_Bill_Info(object): + '''支付宝账单信息''' + + def __init__(self, headers, user, passwd): + ''' + 类的初始化 + headers:请求头 + cookies: 持久化访问 + info_list: 存储账单信息的列表 + ''' + self.headers = headers + # 初始化用户名和密码 + self.user = user + self.passwd = passwd + # 利用 requests 库构造持久化请求 + self.session = requests.Session() + # 将请求头添加到缓存之中 + self.session.headers = self.headers + try: + cookies = pickle.load(open("cookies", "rb")) + for cookie in cookies: + self.session.cookies.set(cookie['name'], cookie['value']) + print u"获取cookies成功!" + except: + print u"未登陆过,需先登录" + self.get_cookies() + if not self.login_status(): + print u"cookies失效,重新登录" + self.get_cookies() + # 初始化存储列表 + self.info_list = [] + + def wait_input(self, ele, str): + '''减慢账号密码的输入速度''' + for i in str: + ele.send_keys(i) + time.sleep(0.5) + + def get_cookies(self): + '''获取 cookies''' + # 初始化浏览器对象 + # sel = webdriver.PhantomJS( + # executable_path='C:\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe') + # sel = webdriver.PhantomJS( + # executable_path='/root/phantomjs/bin/phantomjs') + sel = webdriver.Chrome(executable_path='C:/chromedriver.exe') + sel.maximize_window() + sel.get(Login_Url) + sel.implicitly_wait(3) + # 找到用户名字输入框 + uname = sel.find_element_by_id('J-input-user') + uname.clear() + print u"正在输入账号....." + self.wait_input(uname, self.user) + time.sleep(1) + # 找到密码输入框 + upass = sel.find_element_by_id('password_rsainput') + upass.clear() + print u"正在输入密码...." + self.wait_input(upass, self.passwd) + # 截图查看 + sel.save_screenshot('1.png') + # 找到登录按钮 + button = sel.find_element_by_id('J-login-btn') + time.sleep(1) + print 1 + button.click() + print 2 + sel.save_screenshot('2.png') + if len(re.findall('checkSecurity', sel.current_url)) > 0: + riskackcode = sel.find_element_by_id('riskackcode') + riskackcode.clear() + print u"等待输入验证码:" + msgcode = raw_input() + self.wait_input(riskackcode, msgcode) + button = sel.find_element_by_xpath( + '//*[@id="J-submit"]/input') # ui-button + time.sleep(1) + button.click() + sel.save_screenshot('2.1.png') + print(sel.current_url) + # 跳转到账单页面 + print u"正在跳转页面...." + sel.get(Bill_Url) + sel.implicitly_wait(3) + sel.save_screenshot('3.png') + # 获取 cookies 并转换为字典类型 + cookies = sel.get_cookies() + pickle.dump(cookies, open("cookies", "wb")) + for cookie in cookies: + self.session.cookies.set(cookie['name'], cookie['value']) + # 关闭浏览器 + sel.close() + + def set_cookies(self): + '''将获取到的 cookies 加入 session''' + self.get_cookies() + + def login_status(self): + '''判断登录状态''' + # 添加 cookies + status = self.session.get( + Bill_Url, timeout=5, allow_redirects=False, verify=False).status_code + print(status) + if status == 200: + return True + else: + return False + + def get_data(self): + ''' + 利用 正则表达式解析 html + 并抓取数据, + 数据以字典格式保存在列表里 + ''' + status = self.login_status() + if status: + html = self.session.get(Bill_Url, verify=False).text + # 抓取前五个交易记录 + trades = re.findall('', html) + for trade in trades: + # 做一个 try except 避免异常中断 + try: + # 分别找到账单的 时间 金额 以及流水号 + day = re.findall( + '

.*?(\d{4}\.\d{2}\.\d{2})', trade)[0] + time = re.findall( + '

.*?(\d{2}:\d{2})', trade)[0] + amount = re.findall( + '(.*?) ', trade)[0] + ddh = re.findall( + '.*?(\d{20})', trade)[0] # + print day, time, amount, ddh + except Exception, e: + print e + else: + print u"登录失败" + + +# test: +test = Alipay_Bill_Info(HEADERS, USERNMAE, PASSWD) +test.get_data() + diff --git a/hostloc/README.md b/hostloc/README.md index 9406398..da75747 100644 --- a/hostloc/README.md +++ b/hostloc/README.md @@ -7,4 +7,5 @@ 每天运行一次,每次获取20金币,升元老指日可待2333 -**目前脚本有问题,需修改后才能用** \ No newline at end of file +**目前脚本有问题,需修改后才能用** +**因为crontab定时任务print中文会出错,将脚本里面的print的地方注释** From 4682385f6c6b18ebe58cbc251261b52eb1098b82 Mon Sep 17 00:00:00 2001 From: za2016 <920082975@qq.com> Date: Fri, 20 Oct 2017 13:08:24 +0800 Subject: [PATCH 9/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10e9e8c..647b8c8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 就是一些~~有用的~~Python脚本 1. hostloc:hostloc访问空间获取金币,每天运行一次,每次20金币 -2. zhihu:知乎图片下载器,下载某个问答下面所有的图片 +2. zhihu:知乎图片下载器,下载某个问答下面所有的图片(接口更新,目前已经失效) 3. tumblr:Tumblr爬虫 4. v2ex:v2ex签到脚本 5. fuliba:福利吧签到脚本