我正在尝试从网站上抓取数据。我正在制作一个循环来提取数据并存储在一个变量中,但无法将其保存在 csv 文件中。作为 Python 和 BeautifulSoup 的新手,我并没有走多远。这是代码:
import requests
from bs4 import BeautifulSoup
import csv
r = "https://sofia.businessrun.bg/en/results-2018/"
content = requests.get(r)
soup = BeautifulSoup(content.text, 'html.parser')
for i in range (1,5):
team_name= soup.find_all(class_="column-3")
team_time= soup.find_all(class_="column-5")
for i in range (1,5):
print (team_name[i].text)
print (team_time[i].text)
with open("new_file.csv","w+") as my_csv:
csvWriter = csv.writer(my_csv,delimiter=',')
csvWriter.writerows(team_name)
任何帮助将不胜感激!
相关分类