您的位置:首页 > 编程语言 > Python开发

So cute are you Python 10

2013-10-19 16:09 281 查看
1.Python 实现抓取网页信息

#!/usr/bin/evn python
#coding:utf-8
#FileName:spider_01.py
#Function : grasp an web page from website then show the things that you catch
import urllib
response = urllib.urlopen('http://blog.csdn.net/yxh1157686920')
html = response.read()
print html

2.Python 在linux 下实现根据名字,结束进程

#!/usr/bin/python

import os,re,sys

def kill_by_name(name):
cmd='ps aux|grep %s'%name
f=os.popen(cmd)
regex=re.compile(r'\w+\s+(\d+)\s+.*')
txt=f.read()
if len(txt)< 5:
print 'there is no thread by name or command %s'%name
return

ids=regex.findall(txt)
cmd="kill %s"%' '.join(ids)
os.system(cmd)

if __name__=='__main__':
if len(sys.argv)== 1:
name=raw_input("type the process command name:")
else:
name=sys.argv[ 1]
kill_by_name(name)


3.实现刷博基础功能。

#!/usr/bin/evn python
#coding:utf-8
#FileName:openblog.py
#Function : Open  blog in loop
import webbrowser
import time,os,sys,re
def open():
print '刷新开始。。。\r\n'
for i in xrange( 0,10):
webbrowser.open('http://www.baidu.com')
time.sleep( 2)
n='firefox'
kill_by_name(n)
#结束firefox进程
def kill_by_name(name):
cmd='ps aux|grep %s'%name
f=os.popen(cmd)
regex=re.compile(r'\w+\s+(\d+)\s+.*')
txt=f.read()
if len(txt)< 5:
print '该进程没启动或已经停止:_ %s'%name
return

ids=regex.findall(txt)
cmd="kill %s"%' '.join(ids)
os.system(cmd)

if __name__=='__main__':
open()
web='http://www.126.com'
#splinter(web)

4.实现个人博客刷新

#!/usr/bin/evn python
#coding:utf-8
#FileName:openblog.py
#Function : Open  blog in loop
import webbrowser
import time,os,sys,re
def open():
print '刷新开始。。。\r\n'
#web=raw_input('请输入博客网址:_(example:http://www.yahoo.com/)\r\n:_')
#if web=='':
web='http://home.51cto.com/index.php?s=/space/7743046'
for i in xrange(0,10):
webbrowser.open(web)
time.sleep(2)
n='firefox'
kill_by_name(n)
#结束firefox进程
def kill_by_name(name):
cmd='ps aux|grep %s'%name
f=os.popen(cmd)
regex=re.compile(r'\w+\s+(\d+)\s+.*')
txt=f.read()
if len(txt)<5:
print '该进程没启动或已经停止:_ %s'%name
return

ids=regex.findall(txt)
cmd="kill %s"%' '.join(ids)
os.system(cmd)

if __name__=='__main__':
while True:
open()


5.实现访问别人的博客

#!/usr/bin/evn python
#coding:utf-8
#FileName:openblog.py
#Function : Open  blog in loop
import webbrowser
import time,os,sys,re
def open(num):
print '刷新开始。。。\r\n'
#web=raw_input('请输入博客网址:_(example:http://www.yahoo.com/)\r\n:_')
#if web=='':
web='http://home.51cto.com/index.php?s=/space/00'+str(num)
for i in xrange(0,2):
webbrowser.open(web)
time.sleep(10)
n='firefox'
kill_by_name(n)
#结束firefox进程
def kill_by_name(name):
cmd='ps aux|grep %s'%name
f=os.popen(cmd)
regex=re.compile(r'\w+\s+(\d+)\s+.*')
txt=f.read()
if len(txt)<5:
print '该进程没启动或已经停止:_ %s'%name
return

ids=regex.findall(txt)
cmd="kill %s"%' '.join(ids)
os.system(cmd)

if __name__=='__main__':
global num
num=850
while True:
open(num)
num+=1
print num
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: