fork download
  1. # your code goes here
  2.  
  3. import re,urllib,cookielib,urllib2,time,mimetools,cfscrape,sys,os
  4.  
  5. tred=sys.argv[1]
  6. tredname=re.findall(r'/([^/]+?)$',tred)[0]
  7. tredname=re.sub(r'\.html','',tredname)
  8. prefSos=re.findall(r'^(.+?)/res/',tred)[0]
  9.  
  10. myHeaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1'),('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]
  11. cj=cookielib.CookieJar()
  12. opener1=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  13. opener1.addheaders=myHeaders
  14. urllib2.install_opener(opener1)
  15.  
  16. scraper = cfscrape.create_scraper(js_engine="Node") # returns a CloudflareScraper instance
  17. # Or: scraper = cfscrape.CloudflareScraper() # CloudflareScraper inherits from requests.Session
  18. data=scraper.get(tred).content
  19.  
  20. pics=re.findall(r'href="\.\.(\/src[^"]+?)"',data,re.U+re.S)
  21.  
  22. if pics:
  23. if not os.path.exists('./'+tredname):
  24. os.makedirs('./'+tredname)
  25.  
  26. for pic in pics:
  27. fn='./'+tredname+'/'+re.findall(r'/([^/]+?)$',pic)[0]
  28. if not os.path.exists(fn):
  29. print 'processing %s '%fn,
  30. imagedata=scraper.get(prefSos+pic).content
  31. f1=open(fn,'wb');f1.write(imagedata);f1.close()
  32. print ' done.'
  33.  
  34. print 'all done.'
  35.  
  36.  
Runtime error #stdin #stdout #stderr 0.09s 13408KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 3, in <module>
ImportError: No module named cfscrape