数据存储为json或数据库
作者:互联网
1.数据存储
In [ ]:
import requests
from bs4 import BeautifulSoup
rqq = requests.get('http://www.tipdm.com/tipdm/index.html')
soup = BeautifulSoup(rqq.content, 'lxml')
dat = soup.select('.menu > li > a')
In [ ]:
names = [i.text for i in dat]
href = [i['href'] for i in dat]
print(names, href)
In [ ]:
import json
with open('./temp.json', 'w') as f:
json.dump({'names': names, 'href': href}, f, ensure_ascii=False)
In [ ]:
import os
os.getcwd()
2.参考文章
【创作不易,望点赞收藏,若有疑问,请留言,谢谢】
标签:存储,数据库,BeautifulSoup,dat,json,href,names,import 来源: https://www.cnblogs.com/dongxuelove/p/16434813.html