Python crawler gets the SS QR code on the wtfx.tk

Source: Internet
Author: User

wtfx.tk is a website that shares the free SS account, but he shares only the QR Code. And the latest version of the SS can not scan the two-dimensional code on the page, so it is very troublesome to download the Picture. So I specifically wrote a crawler to save the QR code on the site to a local folder.

The crawler will delete the Pic folder under the relative path and create a new pic folder to store the QR Code. Please use it with Caution.

If there is no Pic folder under the relative path, the crawler will prompt and press Enter to Continue.

The source code is as Follows:

1 #Coding:utf-82 __author__='Liuqi'3 ImportOS4 ImportRe5 ImportSYS6 ImportCopy7 ImportShutil8 ImportUrllib9 ImportChardetTen  one defgethtml (url): apage =Urllib.urlopen (url) -HTML =Page.read () -     returnHTML the  - defgetpngaddr (html): -PNG = R"Pic/\w+[-]?\w+[-]?\w*\.png" -TMP =re.compile (png) +PNG =Re.findall (tmp, Html) -     #Print PNG +      forIinchRange (len (png)): apng[i] = URL +png[i] at      -     returnPNG -  - defgetpngname (pngaddr): -Pngname =copy.deepcopy (pngaddr) -      inPngt = R'pic/(\w+[-]?\w+[-]?\w*) \.' -t =re.compile (pngt) to      forIinchRange (len (pngaddr)): +pngname[i] =re.findall (t, pngaddr[i]) [0] -      the     returnPngname *      $ defgetpng (Addr, Name):Panax NotoginsengUrllib.urlretrieve (Addr,"Pic\\%s.png"%Name) -  the      + if __name__=="__main__": aURL ='http://wtfx.tk/' the  +HTML =gethtml (url) -  $PNGADDR =getpngaddr (html) $     #Print Pngaddr -Pngname =getpngname (pngaddr) -  the     #os.rmdir (' pic ') -     Try:WuyiShutil.rmtree ('pic') the     exceptwindowserror, E: -         Print "couldn ' t rm folder:no such folder!" wuRaw_input ("Press Enter to continue >") -      aboutOs.mkdir ('pic') $  -      forIinchRange (len (pngaddr)): - getpng (pngaddr[i], pngname[i]) -  a #Html_code = chardet.detect (html) [' encoding '] + #Sys_code = sys.getfilesystemencoding () the #print "html is encoding by:", html_code - #print "system is encoding by:", sys_code $ #normal output Web page the #print Html.decode (html_code). encode (sys_code)

Configuration conditions: Make sure that Python2 is installed on your computer.

How to use: Create a new. py file, copy, save, and double-click to run the above Code.

Python crawler gets the SS QR code on the wtfx.tk

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.