Python 字符串正则处理实例

#coding:utf-8


'''
Created on 2017��9��6��

@author: li.liu
'''

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import os
import time
import re

url='http://101.37.179.183'
#url='http://www.baidu.com'

'''
xpath='//*[@id="header"]/div[4]/span[1]/a'
xpath1='//*[@id="header"]/div[4]/span[2]/a'
driver=webdriver.Chrome()
driver.get(url)
#elem=driver.find_element_by_xpath(xpath)
#ActionChains(driver).move_to_element(elem).perform()
#time.sleep(1)
print driver.find_element_by_xpath(xpath1).is_selected()
print 1
driver.quit()

try:
    driver.find_element_by_xpath(xpath1).click()
    
except:
    elem=driver.find_element_by_xpath(xpath)
    ActionChains(driver).move_to_element(elem).perform()
    driver.find_element_by_xpath(xpath1).click()
print 1

n='n'
m='m'
t={n:[1,2],m:[3,4,5]}

l='l'
t[l]=[]
t[l].append(6)
t[l].append(7)
t[l].extend(t[n])

print type(t)
for i in t:
    print i,t[i]


t[l]=[]
print '\n=============='    
for (d,k) in t.items():
    print d,k
'''
'''
a=1
b=2
b=a+b
a=b-a
b=b-a
print a,b

def t(*t):
    print type(t)
    
def h(**t):
    print t
t(1,2)
h(a={},b=2,c=3)

print '需求分析'
print ''
'''

c=0

'''
for i in a:
    try:
        print int(i)
        c+=1
    except:
        pass
print c
'''

a='abcd1.2dbdf4dd32da2dfs9df'
s=re.findall('\d', a)
t=''
for i in s:
    t=t+i
print t

s=re.compile('\D')
c=re.sub(s,'',a)
print c

  

posted @ 2017-12-18 16:01  LLSix  阅读(362)  评论(0编辑  收藏  举报