輸入歌手獲得歌曲並寫入檔案

2021-08-15 21:12:21 字數 1367 閱讀 6143

# -*- coding:utf-8 -*-

import requests

import json

import os

while true:

name = input("請輸入歌曲名稱:")

if not name.strip():

break

if not os.path.exists('name.txt'):

with open('name.txt', 'w',encoding='utf-8') as f:

f.write('')

with open('name.txt','r',encoding='utf-8') as f:

name_list = f.readlines()

if name+'\n' in name_list:

print('該名稱已被搜尋')

continue

else:

with open('name.txt', 'a',encoding='utf-8') as f:

f.write(name)

f.write('\n')

# if not name:

# break

start_page = 0

number = 25

#將動態引數放到params字典裡面

response = requests.get("",params=)

# print(response.text)

#json的key和value不能用單引號括起來

result = response.text.replace("'",'"').replace(

' ','')

# print(result)

json_obj = json.loads(result)

# print(json_obj)

song_list = json_obj['abslist']

for song in song_list:

print(song.get('songname','沒有歌曲名稱'))

# f = open('song.txt','a',encoding='utf-8')

# f.write(song.get('songname','沒有歌曲名稱'))

# f.write('\n')

# f.close()

#以上四句簡化版

with open('song.txt','a',

encoding='utf-8')as f:

f.write(song.get('songname', '沒有歌曲名稱'))

f.write('\n')

解析檔案並寫入檔案裡

ifndef analys h define analys h include include object.h define fgetsmax 6 1024 1024 獲取一行資料的最大值6m class object class analys object char v,int l value ...

監聽Log 並寫入檔案

public class notelog public static void stopnotelog private static void startnotelogthread catch ioexception e finally readlogthread.start private sta...

查詢Mysql並寫入檔案

conding utf 8 import pymysql import os import sys 開啟資料庫連線 db pymysql.connect 10.33.85.145 root uxx 2013 使用 cursor 方法建立乙個游標物件 cursor runsql db.cursor 使...