我只想在某个日期之后从表中提取数据。下面的代码获取数据中的第一个日期(附url),但我如何创建say for循环,以便仅从say 2020年10月11日和之前的所有行中提取数据
我想创建一个for循环来提取此表中某个日期之前的所有数据(table table hover small horsePerformance)
http://www.harness.org.au/racing/horse-search/?horseId=813476
with requests.Session() as s:
try:
webpage_response = s.get(horseurl, headers=headers)
except requests.exceptions.ConnectionError:
r.status_code = "Connection refused"
soup = bs(webpage_response.content, "html.parser")
horseresult6 = soup.find('table', class_='table table-hover small horsePerformance')
daysbetween = horseresult6.find('td', class_='date').get_text().strip()
daysbetween24 = horseresult6.find('td', class_='date').find_next('td', class_='date').get_text().strip()
不过我觉得应该是这样的
for tr in horseresult6.find_all('tr')[1:]:
daysbetween = tr.find('td', class_='date').get_text().strip()
if xdate > daysbetween:
do something
else:
continue
当我尝试这个时,它似乎不起作用
您可以使用
<
和>
运算符比较日期以下是方法:
输出:
时光倒流
输出:
相关问题 更多 >
编程相关推荐