import numpy as np
from pandas import Series, DataFrame
import os
import requests
from bs4 import BeautifulSoup
def get_urls(url):
response = requests.get(url).text
bs = BeautifulSoup(response, "html.parser")
hrefs = bs.find("table", id="main_table_countries_today").find_all("tbody")[0].find_all("tr", attrs={
"class": ""})
urls = []
labels = []
for i, href in enumerate(hrefs):
try:
urls.append(href.td.a.get("href"))
labels.append(href.td.a.text.replace(" ", ""))
except Exception as e:
print(e)
return urls, labels
def get_data(url, label):
print(label)
response = requests.get(url).text
bs = BeautifulSoup(response, "html.parser")
scs = bs.select("script")
data_1 = []
if label in np.array(
["UK", "Turkey", "Russia", "Netherlands", "Peru", "Portugal", "Ecuador", "Ireland", "Singapore", "UAE",
"Qatar", "Indonesia", "Romania", "S.Korea", "Belarus", "Serbia", "Philippines", "Nicaragua", "Switzerland",
"Czechia", "DominicanRepublic", "Malaysia", "Norway", "Ukraine", "Bangladesh", "Colombia", "SouthAfrica",
"Egypt", "Morocco", "Moldova", "Algeria", "Kuwait", "Kazakhstan", "Bahrain", "Greece", "Hungary",
"Croatia", "Oman", "Uzbekistan", "Iraq", "Armenia", "Azerbaijan", "Cameroon", "Ghana",
"Afghanistan""BosniaandHerzegovina", "NewZealand", "Lithuania", "Slovenia", "NorthMacedonia", "Slovakia",
"Afghanistan", "BosniaandHerzegovina", "Cuba", "Bulgaria", "Nigeria", "IvoryCoast", "HongKong", "Djibouti",
"Guinea", "Tunisia", "Bolivia", " Cyprus", "Latvia", "Andorra", "Albania", "Lebanon", "CostaRica", "Niger",
"Kyrgyzstan", "Estonia", "Cyprus", "Andorra", "Senegal", "BurkinaFaso", "Honduras", "Uruguay", "SanMarino",
"ChannelIslands", "SriLanka", "Georgia", "Guatemala", "Malta", "Jordan", "DRC", "Somalia", "Taiwan",
"Mayotte", "Mali", "Kenya", "Palestine", "Mauritius", "Venezuela", " Montenegro", "IsleofMan", "Bahamas",
"Barbados"
爬取疫情数据
最新推荐文章于 2022-11-01 10:33:43 发布