Skip to main content

How do I find a tag using BeautifulSoup?

I am trying to scrape a German Billiard League website for results, to tabulate and submit to a rating system that requires a certain format. I am no python expert, but I have muddled through how to pull a complete list of links from the root League page, and to get Date, Home/Visitor teams, and now I am trying to capture individual match data.

Here is the relevant HTML:

<tr>
<td colspan="3" nowrap="" rowspan="2" width="100"><b>
                                Spiel 2<br/>8-Ball                      </b>
</td>
<td class="home up" colspan="6" valign="top">Christian Fachinger</td>
<td class="visitor up" colspan="7" valign="top">Michael Schneider</td>
</tr>
<tr>
<td class="home down" colspan="6" valign="top">7</td>
<td class="visitor down" colspan="7" valign="top">4</td>

Site: https://hbu.billardarea.de/cms_leagues/matchday/344947

I am trying to find the "td" tag that contains the text string "Spiel 2". I should then be able to pull the game - "8-ball", and then move on to figuring out how to capture the data inside the relevant "class" tags. For the life of me, I cannot get a result back. I have tried many permutations of various soup commands, but either get a "None", or "[]". I "think" it might have something to do with the extra spaces, but have tried various regex-centric commands, but have not been able to "select" this td tag to do further data gathering.

What am I doing wrong? I know I am not coding this in the most efficient manner, and this is the first time I have tried to write a web scraper, and in general, am a python newb.

'''

import requests
import re
import os
from bs4 import BeautifulSoup

URL = "https://hbu.billardarea.de/cms_leagues/plan/7870/10406"

def import_all_links():
    page = requests.get(URL).text
    soup = BeautifulSoup(page, "html.parser")
    path = soup.select("a[href*=matchday]")

    for link in path:
        file1 = open("league.txt", "a")  # append mode
        file1.write("https://hbu.billardarea.de" + link['href'] + '\n')
        file1.close()

def get_date():
    links_file = open(r'C:\Users\Russ\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.10\league.txt', "r") 
    for day_link in links_file:
        day_link = day_link.rstrip("\n")
        soup = requests.get(day_link).text
        day_links_parse = BeautifulSoup(soup, "html.parser")
        date = day_links_parse.select('label:contains(Datum)')
        league = day_links_parse.select('label:contains(Saison)')
        home = day_links_parse.find(attrs={"class": "home"}).text
        home = home.partition(":")[2]
        visitor = day_links_parse.find(attrs={"class": "visitor"}).text
        visitor = visitor.partition(":")[2]
        print(day_links_parse)
        **play_table = day_links_parse.td.find_all(text = re.compile('Spiel 2'))**  <<<<< Issue
        **print(play_table)**                                                 <<<<< Returns 0 results

        for item in date:
            date = item.next_sibling.next_sibling.text
            date = date.partition(" ")[0]
            date = date.split(".")
            date = date[1] + "\\" + date[0] + "\\" + date[2]
        for item in league:
            league = item.next_sibling.next_sibling.text
            league = league.partition(" ")[0]

        print(date, ",", league, ",", home, " (H) vs ", visitor, "(V)", sep='')

import_all_links()
get_date() '''


source https://stackoverflow.com/questions/70475129/how-do-i-find-a-tag-using-beautifulsoup

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data