python爬蟲的beautifulsoup庫的使用
以下為爬去985高校的例子:
import requests
from bs4 import beautifulsoup #從bs4中引入beautifulsoup庫
import re
url=
""r=requests.get(url)
soup=beautifulsoup(r.text,
"html.parser"
)#使用html.parser對爬取的源**進行解析
for tr in soup.tbody:
#子標籤可以使用for in從父標籤中提取出來
iflen
(tr)==9
:list
=tr.contents #可以使用contents提取標籤的子標籤並生成列表
(list[1
].text)
(list[3
].string)
#可以利用string,text,get_text提取標籤中的文字
iflen
(tr)==7
:list
=tr.contents
(list[1
].string)
Python學習筆記初識beautifulsoup
今天上午在電腦上把 python簡明教程 大略看完了,對python的基本語法和用法熟悉了一些。下午開始看beautifulsoup,用 這個教程安裝成功 自從把python路徑加到環境變數裡面,覺得開發環境好用了許多,好吧是我之前太菜,其實還因為之前我看的 笨辦法學python 裡面好像就沒有說環...
python的包 python的包
1.把解決一類問題的模組放在同乙個資料夾裡,這個資料夾就是包 2.通過import或是from.import匯入時必須遵循乙個原則 a 凡是在匯入時帶點的,點的左邊都必須是乙個包,否則非法 b 匯入後,使用時點的左邊可以是包,模組,類,函式 它們都可以用點的方式調節用自己的屬性 c from.imp...
python的語句 Python的語句
python中的兩種語句 1 if條件控制語句 格式 if a int input 請輸入第乙個數 b int input 請輸入第二個數 if a b print a比b小 if else a int input 請輸入第乙個數 b int input 請輸入第二個數 if a b print a...