标签:python

python

BeautifulSoup的使用

BeautifulSoup的使用
获取第一个标签的内容 from bs4 import BeautifulSoup file = open('baidu.html', 'rb') html = file.read() bs = BeautifulSoup(html, 'h...

5年前 (2020-10-18) 喜欢

python

python urllib的测试

python urllib的测试
使用urllib读取网页 get res = urllib.request.urlopen('https://www.wanjunshijie.com') print(res.read().decode('utf-8')) 使用urllib p...

5年前 (2020-10-12) 喜欢

python

python异常处理

python异常处理
错误 文件未找到报错 print('test') f = open('text.txt', 'r') print('text2') try捕获异常 不报错 try: print('test&#...

5年前 (2020-10-10) 喜欢

python

python文件操作

python文件操作
打开文件 f = open('text.txt', 'w') #打开文件 写模式,文件不存在就新建 f.close() #关闭文件 写入操作 f = open('text.txt', 'w') #打开文件 写...

5年前 (2020-10-10) 喜欢

python

python 函数

python 函数
定义函数 def printinfo(e): print('=-----------=') print(e) printinfo('ceshi') 带返回值的函数 def add2num(a, b): c = a + ...

5年前 (2020-10-09) 喜欢

python

python 字典

python 字典
字典的定义 info = {'name': '吴彦祖', 'age': 18} 字典的访问 info = {'name': '吴彦祖', 'age': 18} print(inf...

5年前 (2020-10-09) 喜欢

python

python 元组 Tuple

python 元组 Tuple
tuple 与 list 类似,tuple不能修改,tuple写在小括号内,元素间用逗号分隔。 元组的元素不可变,但是可以包含可变对象入list. 定义一个只有1个元素的tuple,必须加逗号。 tup2 = (50,) tupl = ('abc', ...

5年前 (2020-10-08) 喜欢

python

python列表

python列表
列表 列表索引值以0为开始值,-1位从末尾开始值 列表可以完成大多数集合类的数据结构实现 列表中元素的类型可以不同,支持数字 字符串甚至包括列表 列表是写在[]之间用逗号分隔的元素列表 列表可以使用+操作符进行拼接,使用*重复 列表可以存储混合类型 namelist = [] ...

5年前 (2020-10-07) 喜欢

python

python 字符串

python 字符串
python 字符串使用单引号双引号三引号括起来。 word = '字符串' sentence = "一个句子" paragraph = """ 则是段落 这是多行 """ prin...

5年前 (2020-10-05) 喜欢