我编写了一个从网站抓取数据的代码,运行正常,但我想将它们导出到EXCEL文件中.
我是Python的新手,所以我不知道我应该做什么.
我想到pandas
,但我的输出是join
的打印,所以我没有找到一个好的解决方案.
这是我的代码:
from requests_html import HTMLSession
import pandas as pd
import tabulate
from tabulate import tabulate
matchlink = 'https://www.betexplorer.com/football/serbia/prva-liga/results/'
session = HTMLSession()
r = session.get(matchlink)
allmatch = r.html.find('.in-match')
results = r.html.find('.h-text-center a')
# search for elements containing "data-odd" attribute
matchodds = r.html.find('[data-odd]')
odds = [matchodd.attrs["data-odd"] for matchodd in matchodds]
idx = 0
for match, res in zip(allmatch, results):
if res.text == 'POSTP.':
continue
print(f"{match.text} {res.text} {', '.join(odds[idx:idx+3])}")
idx += 3
谢谢你的帮忙