数据存储为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.参考文章

【创作不易,望点赞收藏,若有疑问,请留言,谢谢】

posted @ 2022-07-01 15:28  东血  阅读(51)  评论(0编辑  收藏  举报

载入天数...载入时分秒...