DKethan commited on
Commit
aaa1814
Β·
verified Β·
1 Parent(s): 0970329

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -32,31 +32,37 @@ def get_match_links_from_main_page():
32
 
33
  soup = BeautifulSoup(response.text, "html.parser")
34
 
35
- links = []
36
  all_a_tags = soup.find_all("a", href=True)
37
- print(f"πŸ” [CRAWL] Total <a> tags found: {len(all_a_tags)}\n")
38
 
39
- for i, tag in enumerate(all_a_tags):
40
- href = tag['href']
41
- text = tag.get_text().strip()
 
42
 
43
- # Print every link text + href
44
- print(f"[A TAG {i+1}] TEXT: '{text}'")
45
- print(f" HREF: {href}\n")
46
 
47
- # Only keep match score links
48
- if "match-full-scores" in href:
 
 
49
  full_url = BASE_URL + href
50
- print(f"βœ… [MATCH LINK DETECTED] {text} -> {full_url}")
51
- links.append((text, full_url))
 
 
52
 
53
- print(f"\nβœ… [DONE] Valid match links extracted: {len(links)}")
 
 
54
  return links
55
 
56
  except Exception as e:
57
  print(f"❌ [CRAWL ERROR] Failed to fetch match links: {e}")
58
  return []
59
 
 
60
  # --- Crawl each link and extract score ---
61
  def get_scores_from_links(team_name=None):
62
  print("🟑 [STEP 1] Start crawling for scores...")
 
32
 
33
  soup = BeautifulSoup(response.text, "html.parser")
34
 
 
35
  all_a_tags = soup.find_all("a", href=True)
36
+ print(f"πŸ” [CRAWL] Total <a> tags found: {len(all_a_tags)}")
37
 
38
+ links = []
39
+ for i in range(len(all_a_tags) - 1):
40
+ tag = all_a_tags[i]
41
+ next_tag = all_a_tags[i + 1]
42
 
43
+ text = tag.get_text().strip()
44
+ href = tag['href']
 
45
 
46
+ # Looking for IPL match result + scorecard links
47
+ if "cricket-scores" in href and any(team.lower() in text.lower() for team in IPL_TEAMS):
48
+ title = text
49
+ result = next_tag.get_text().strip()
50
  full_url = BASE_URL + href
51
+ print(f"\n🎯 [MATCH FOUND]")
52
+ print(f"🏷️ Title: {title}")
53
+ print(f"πŸ“Š Result: {result}")
54
+ print(f"πŸ”— Link: {full_url}")
55
 
56
+ links.append((f"{title} – {result}", full_url))
57
+
58
+ print(f"\nβœ… [DONE] Total match results extracted: {len(links)}")
59
  return links
60
 
61
  except Exception as e:
62
  print(f"❌ [CRAWL ERROR] Failed to fetch match links: {e}")
63
  return []
64
 
65
+
66
  # --- Crawl each link and extract score ---
67
  def get_scores_from_links(team_name=None):
68
  print("🟑 [STEP 1] Start crawling for scores...")