當前位置:成語大全網 - 新華字典 - Python beautifulsoup 獲取標簽中的值 怎麽獲取?

Python beautifulsoup 獲取標簽中的值 怎麽獲取?

age = soup.find(attrs={"class":"age"}) #妳這裏find只要壹個attrs參數不會報錯。

if age == None: #簡單點可以用 if not age:

print u'沒有找到'

else:

soup.find(attrs={"class":"name"})

#否則用findAll找出所有具有這個class的tr

tr = html.find("tr", attrs={"class":"show_name"})

tds = tr.findAll("td")

for td in tds:

print td.string # 或許不是string屬性,妳可以用dir(td)看看有哪些可用的。

擴展資料:

1、如果是函數定義中參數前的*表示的是將調用時的多個參數放入元組中,**則表示將調用函數時的關鍵字參數放入壹個字典中。

1)如定義以下函數:

def func(*args):print(args)

當用func(1,2,3)調用函數時,參數args就是元組(1,2,3)

2)如定義以下函數:

def func(**args):print(args)

當用func(a=1,b=2)調用函數時,參數args將會是字典{'a':1,'b':2}

學python的同時壹定會接觸到其他技術,畢竟光會python這門語言是不夠的,要看用它來做什麽。比如說用 python做爬蟲,就必須接觸到html, http等知識。

python是現在最火的數據分析工具語言python的進階的路線是數據清洗,爬蟲,數據容器,之後是卷積,線性分析,和機器學習,區塊連,金融方面的量化等高端進階。