So cute are you Python 10

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值