首先,题意需要明确,让我门尝试nothing的值,我们猜测这是一个变量 http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=abc 页面返回了:and the next nothing is 6711 接着我们尝试:http://www.pythonchallenge…….
Python Challenge Level 3 re.findall
Python Challenge Level 2 re.findall
Python Challenge Level 1 string.maketrans
最近在做python Challenge ,把里边的知识点一起整理一下、
1 2 3 4 5 6 7 8 9 10 11 12 |
import string original = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc " \ "dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq " \ "rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu " \ "ynnjw ml rfc spj." table = string.maketrans( "abcdefghijklmnopqrstuvwxyz", "cdefghijklmnopqrstuvwxyzab" ) print original.translate(table) |
最主要还是要看提示,但是题目最后一句是apply to the url ,因为url是map,用map作为original得到的结果是ocr,所以,下一地址为 http://www.pythoncha……
如何Kill掉远程到我们服务器上的ssh
python 中的 and or
python 使用 optparse 处理命令行参数
python的optparse给我他们提供了很好的命令行处理参数的功能,让我们写的脚本可以拥有帮助,一个好的脚步怎么能没有提示信息呢,顿时高大上起来
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from optparse import OptionParser def main(): usage = "usage: %prog [options] arg" parser = OptionParser(usage) #先创建了一个类 parser.add_option("-f", "--file", dest="filename", help="read data from FILENAME") #上边的这句话的详细解释为:首先,我们可以使用 -f 或者 --file来传入一个参数变量,这个变量存在的目的是"read data from FILENAME",然后脚本接收到这个值之后,会存储到options.filename这个变量中让我们使用 parser.add_option("-v", "--verbose",action="store_true",dest="verbose",help="show some debug message") #这句话的意思是说我们要传入一个-v 参数,这个参数是不需要后跟值的,只是表示打开或者关闭,这个-v打开的时候, -q就是不打开的,因为一个是安静模式,一个是显示模式,所以他俩存入了相同的变量options.verbose parser.add_option("-q", "--quiet",action="store_false", dest="verbose",help="run quite") #同上 #创建的类通过add_option来添加参数 (options, args) = parser.parse_args() #上边这句就是用我们创建的类和已经添加的规则来处理命令行参数了 if len(args) != 1: #这句话的意思是说,我们出来我们的-v -f a.txt 后便还要单独再跟一个参数(或多个)python help1.py -v -f abc.txt arg1 arg2(这个地方做了判断,只能传一个) parser.error("incorrect number of arguments") if options.verbose: print "reading %s..." % options.filename if __name__ == "__main__": main() </code> |
脚本还会帮我们自动生成帮助信息,就是我们输入参数-h 或者–help的时候,显示内容就是我们add_option的时候添加……
如何写一个高大上的Python脚本 带提示信息的python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#!/usr/bin/env python # coding=utf-8 import getopt,sys try: opts,args = getopt.getopt(sys.argv[1:],"hvo:",["help","out="]) #上一行中,hvo是三个不同的参数,“”中间的表示是短参数,例如我们常用的-a -l -c ,这些重有些是需要参数的,有些是不需要的,不需要参数的例如 -h, 我们不需要后跟参数,这种是开关类的,但是有一些是需要参数的,例如 -o abc.txt,其中三个参数是h v 是不需要参数的,o 因为后便跟了:,所以需要参数,[]中间的是长参数,例如 --help,也分为 开关类和需要值的,带=的就需要值 print args for o,a in opts: #print '%s : %s' % (o,a) if o in ("-h","--help"): print 'you have input the "-h" or "--help" ,so the help info is Usage: sys.argv[0] --help' if o in ("-v"): print 'you have input the "-v",so will print debug info' if o in ("--out"): print 'you have input the "--out" ,so we have something to out',a except getopt.GetoptError: print 'something wrong' |
python 获取网站状态码
python抓取指定网站内容并分析BeautifulSoup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#!/usr/bin/env python # coding=utf-8 from bs4 import BeautifulSoup import urllib2 import socket response=urllib2.urlopen('http://www.503error.com',timeout=10) html_data=response.read() print html_data soup=BeautifulSoup(html_data) print soup.prettify() print 'start to analayse---------------' #for tag in soup.find_all(rel="bookmark"): # print tag #print 'entry-title-----------------------' #for tag in soup.find_all(class_="entry-title"): # print tag title_soup=soup.find_all(class_='entry-title') #print 'firt-article----------------' #print title_soup[0] tag_a = title_soup[0].a.contents print '网站http://www.503error.com最新的文章为:',tag_a[0] |