网上找了个接口,直接用python去跑循环拿数据。
import requests
country_list = []
def get_country(ip_str):
data = {
"ip": str(ip_str)
}
url = "https://api.uutool.cn/ip/location_batch/"
response = requests.post(url, data=data).json()['data']
for row in response['rows']:
country_list.append(row['country'])
def country_persentage():
countrys = set(country_list)
for country in countrys:
persentage = '{:.2f}%'.format(int(country_list.count(country)) / len(country_list) * 100)
print(f"{country} 占据 {persentage}")
''''
统计每个国家出现的次数,
国家的次数 / 总数 = 百分比
'''
if __name__ == '__main__':
with open("/Users/Desktop/ip.txt") as f:
a = 0
str1 = ""
for i in f.readlines():
a = a + 1
str1 = str1 + f"{i}"
if a % 100 == 0:
get_country(str1.replace("\n", "|"))
str1 = ""
country_persentage()