考试内容

python第三方库requests,pymongo,bs4等用法总结

requests; 请求网站,网页
importrequests
help(requests
r = requests.get('https://www.baidu.com')

pymongo ; 连接数据库
数据库 : iaaf
use iaaf
show tables ------- athletes
db.athletes.find()
pymongo ; db = pymongo.MongoClient().iaaf
for i in db.athletes.find():
print i

bs4 ; from bs4 import BeautifulSoup 解析页面
html = r.content
soup = BeautifulSoup(html, 'html.parser')
type(soup)
l=soup.find_all("a")for i in l:
print i.text
print i.get("href")

猜你喜欢

转载自blog.51cto.com/14375816/2409325