【发布时间】:2021-05-17 04:02:39
【问题描述】:
我正在尝试使用 beautifulsoup 将日期值放入数据框中。
我想得到“2021 年 5 月 17 日”
我该怎么做?
我现有的代码:
import pandas as pd
from selenium import webdriver
from bs4 import BeautifulSoup as bs
browser = webdriver.Chrome()
urls = {
"https://www.oddsportal.com/matches/soccer/"
}
class GameData:
def __init__(self):
self.date = []
def parse_data(url):
browser.get(url)
df = pd.read_html(browser.page_source, header=0)[0]
html = browser.page_source
soup = bs(html, "lxml")
cont = soup.find('div', {'id': 'wrap'})
content = cont.find('div', {'id': 'col-content'})
content = content.find('table', {'class': 'table-main'}, {'id': 'table-matches'})
main = content.find('th', {'class': 'first2 tl'})
if main is None:
return None
count = main.findAll('a')
country = count[0].text
league = count[1].text
如何获取df 中的日期值?
【问题讨论】:
-
那么你能找到日期还是只想用那个日期创建一个数据框??
-
我有一个来自这个页面的数据框。我希望将日期附加到数据框中。另外,如果我可以将其转换为日期时间对象,那就太好了。
标签: python pandas web-scraping beautifulsoup