赞
踩
1.做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用**生成激活码**(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)
- #!/user/bin/env python
- # -*- coding:utf-8 -*-
- import random, string
-
- forSelect = string.ascii_letters + "0123456789"
-
- def generate(count, length):
- # count = 200
- # length = 20
-
- for x in range(count):
- Re = ""
- for y in range(length):
- Re += random.choice(forSelect)
- print(Re)
-
- if __name__ == "__main__":
- generate(200, 20)
'运行
3.一个HTML文件里面,找出里面的正文
#!/user/bin/env python # -*- coding:utf-8 -*- import re fin=open('test.txt','r') str=fin.read() reObj=re.compile('\b?(\w+)\b?') #\b匹配单词的开始或结束 words=reObj.findall(str) wordDict=dict() for word in words: if word.lower() in wordDict: wordDict[word.lower()]+=1 else: wordDict[word]=1 for key,value in wordDict.items(): print '%s: %s' % (key ,value)
- import requests,re
- from bs4 import BeautifulSoup
-
- url = 'http://linyii.com'
- data=requests.get(url)
- r = re.findall(r'<body>[\s\S]*</body>',data.text)
- print(r[0])
-
- print('---------------------------------------------------------------')
- soup = BeautifulSoup(data.text,'html.parser')
- print(soup.body.text)
4.一个HTML文件里面,找出里面的链接
- import requests,re,os
- from bs4 import BeautifulSoup
-
- url = 'http://linyii.com'
- data=requests.get(url)
- # urls = re.findall(r'<a.*href=\"(.*?)\".*</a>',data.text)
- # print(urls)
-
- soup = BeautifulSoup(data.text,'html.parser')
- urls = soup.findAll('a')
- for u in urls:
- print(u['href'])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。