Python常见问题和技巧
2015-11-30 17:34
645 查看
Python常见问题和技巧
参数的class和class_使用
在某些函数的参数中,可能需要用到有名参数class,因为class又是语言本身的关键字,所以使用class_。例如:
from bs4 import BeautifulSoup ...
# 指定class查找html源码 >>> for t in soup.find_all(class="sister"): print(t) SyntaxError: invalid syntax
应换成:
>>> for t in soup.find_all(class_="sister"): print(t) <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a> <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a> <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>
相关文章推荐
- Python+Selenium自动化
- python subprocess,ConfigParser
- Python的星号(*、**)的作用
- python地理处理包——pyproj官方中文文档
- 我的sublime python环境配置
- python 对象和引用
- 对python装饰器的理解(来自百度经验,侵删)
- Python 虚拟环境:Virtualenv
- Python使用getopt处理命令行操作
- Python列表list
- Beginning Python Chapter3
- python getattr获取对象属性
- 递增递减显示数字列表1-10
- 排序算法一:内部排序算法Python实现
- Python编程核心之makeTextFile.py和readTextFile.py
- 利用Python学习RabbitMQ消息队列
- Python: Neural Networks
- python的位置参数和名称参数的包装注意事项
- Python设计模式系列之一: 用模式改善软件设计
- Python中super关键字的作用