import requests
from bs4 import BeautifulSoup
import csv
f = open("data2.csv", 'w', encoding="utf-8")
csvwriter = csv.writer(f)
url = 'https://www.maigoo.com/news/603854.html'
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"
}
res = requests.get(url, verify=False, headers=headers)
page = BeautifulSoup(res.text, "html.parser")
table = page.find("table", attrs={"class": "mod_table table1 fcolor30"})
trs = table.find_all('tr')[1:]
for tr in trs:
tds = tr.find_all('td')
rank = tds[0].text
name = tds[1].text
country = tds[2].text
csvwriter.writerow([rank, name, country])
print(rank, name, country)
f.close()
test2
于 2023-06-13 14:33:17 首次发布