python3.6基础知识_python基础知识——基于python3.6

语法糖

# # -*- coding: utf-8 -*-

# #-------------

# #--------- 语法糖---------------

# #-----------------------------------

# def a(fun):

# print('aaaaaa')

# fun()

# print('bbbbb')

# return (

#

# )

# @a

# def fun():

# print('hello')#要注入的

正则match

# 搜索

#---------------------

# import re

# point = re.match('dd','www.nuaud.nadn')

# if point is not None:

# print(point.span())

# else:

# print('no')

# import re

用正则表达式搜索8位或11位手机号

------------------------------

#电话号码

#---------------------------

# point = re.search('^[0-9]{8}$|^[0-9]{11}$', '125667889999')

# if point is not None:

# print(point.span())

# else:

# print('no')

#------------------

用正则表达式查找日期

#查找日期

#-----------------------------

# 2017-03-05

# import re

# point = re.search('^[0-9]{4}-[0-1]{0,1}-[0-3]{0,1}-[0-9]{1}', '125667889999')

# if point is not None:

# print(point.span())

# else:

# print('no')

get方式

#get方式

#--------------------------

# import urllib.request

# f=urllib.request.urlopen("http://m.cnblogs.com/")

# s=f.read()

# print(s)

#------------

正则提取

#正则提取

# #--------------------------

# import re

# from urllib.request import urlopen

# f = urlopen("http://www.meishij.net/")

# s = f.read()

# s=s.decode('utf-8')

# mm = re.findall('(.*)',str(s))

# print((mm))

# print((mm)[0][1])

爬虫爬一个网站

#爬招聘网站------------------------------

#---------------------------------

# import re

# from urllib.request import urlopen

# from urllib.request import Request

# headers = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}

# url = "http://sou.zhaopin.com/jobs/searchresult.ashx?jl=%E5%8C%97%E4%BA%AC&kw=python&sm=0&p=1"

# req_timeout = 5#______________________________--------------添加模拟浏览器协议头

# req = Request(url=url,headers=headers)

# f = urlopen(req,None,req_timeout)

# s = f.read()

# s = s.decode('utf-8')

# mm = str(s)

用代码新建一个文件,并写入txt文档

#新建file 写入txt——————————————————

#————————————————

# f=open("file/test.txt",'w')

# f.write("First line 1.\n" )

# f.write("First line 2.\n" )

# f.write("First line 3.\n")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值