基礎知識點
python格式化
? ? ? ? ?python格式化
? ? ? ? ? ? ? ? ?數(shù)字格式化
? ? ? ? ? ? ? ? ?python
? ? ? ? ? ? ? ? ?print("{:.2f}".format(3.1415926))#設置兩位小數(shù)
? ? ? ? ? ? ? ? ?print("{:.2%}".format(0.25))#百分比
? ? ? ? ? ? ? ? ?print("{:^10}".format("aaaaa"))#居中
? ? ? ? ? ? ? ? ?print("{:<10}".format("aaaaa"))#左對齊
? ? ? ? ? ? ? ? ?print("{:>10}".format("aaaaa"))#右對齊
? ? ? ? ? ? ? ? ? 結果? ? ? ? python
? ? ? ? 3.14
? ? ? ? 25.00%
? ? ? ? aaaaa
? ? ? ? aaaaa
? ? ? ? aaaaa
中文輸出排版
print("{0:{1}^10}".format("感悟",chr(12288)))#居中
print("{0:{1}^10}".format("你是不是",chr(12288)))#居中
print("{0:{1}^10}".format("哈哈哈",chr(12288)))#居中
print("{0:{1}^10}".format("你是環(huán)境嗎",chr(12288)))#居中
print("{0:{1}^10}".format("很額額哈雞兒哈酒",chr(12288)))#居中文章來源:http://www.zghlxwxcb.cn/news/detail-800774.html
python爬蟲知識點
Beautiful Soup4庫
安裝BeautifulSoup4庫
- 導入:from bs4 import BeautifulSoup
正則表達式
正則表達式是用來簡潔表達一組字符串的表達式。
主要用在字符串匹配中
正則表達式常用字符串
. 表示任何單個字符
[] 字符集,對單個字符給出取值范圍,例:[abc]表示a,b,c中的一個,[a-z]表示a到z中的一個字符
[^]非字符集,對單個字符給出排除范圍,例[^abc]表示非a或b或c的單個字符
前一個字符0次或無線次擴展,例abc*表示ab、abc、abcc、、、
前一個字符1次或無限次擴展,例abc+表示abc、abcc、、、、
? 前一個字符0次或者1次擴展,例abc?表示ab、abc
| 左右表達式任意一個,例abc|def表示abc、def
{m} 擴展前一個字符m次,例ab{2}c表示abbc
{m,n}擴展前一個字符m至n次(含n),例ab{1,2}c表示abc,abbc
^ 匹配字符串開頭,例^abc表示abc且在一個字符串的開頭
$ 匹配字符串結尾
()分組標記,內(nèi)部只能使用|操作符,例(abc)表示abc,文章來源地址http://www.zghlxwxcb.cn/news/detail-800774.html
到了這里,關于python爬蟲相關的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!