I am trying to find the problem within this code

obabtd

I was trying to run the code below when scraping data from a website:

for match in match_data:
    home_team.append(match.find('th', class_='fhome').get_text())
    score.append(match.find('th', class_='fscore').get_text())
    away_team.append(match.find('th', class_='faway').get_text())

then I got the error message below:

NameError: name 'home_team' is not defined

I tried to USE the code below:

for match in match_data:
    hometeam = home_team.append(match.find('th', class_='fhome').get_text())
    tscore = score.append(match.find('th', class_='fscore').get_text())
    awayteam = away_team.append(match.find('th', class_='faway').get_text())

But the error message is still the same as above

MatBailie

Initialise all three variables as empty lists ([] or list()) at the start of your code (before your loop).

Otherwise, you have nothing to append your values to. (append() is just a method that exists on a list object. Without storing a list in the variable first, there is nothing to call append() from.)

home_team = []
score = []
away_team = []

for match in match_data:
    home_team.append(match.find('th', class_='fhome').get_text())
    score.append(match.find('th', class_='fscore').get_text())
    away_team.append(match.find('th', class_='faway').get_text())

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am trying to implement the ajax technology but unable to find whats the problem

I am trying to find a file in a directory, but the shell code snippet is not detecting it

I am trying to find the time duration within a column with reference to change in activity status of a key column in python

I am trying to use a find function to find room and assign a name to the adjacent cell, however I am getting a code 91 in the debugger

I am trying to solve this leetcode problem

What is the problem with my code , I am trying to search in the stack with an internall and external method

What is wrong with this code? I am trying to make a program that computes tax and tips and ran into this problem

I am trying to find the range of these data types

I am trying to find the nth binary palindrome

I am trying to find the duplicate of elements in an array

I am trying to write a Python code that reads each item in a list and add and find the average of that list with certain conditions

I am trying to find the height of a Binary tree with this code, but it keeps returning 0, can someone tell me why?

I am trying to understand the following javascript code

I am trying the following code , but it is throwing exception

I am trying to make a moving object but the code isn't doing anything. I'm wondering what the problem is?

I am trying to call a method in a class that is within a class

I am trying to call a function within itself, but it does not work for me

I am trying to creat a program to display the months and the days within the month

Is there a problem with my code or the API I am using?

I am trying to draw a UML diagram for my code but cannot find any good examples. Is this diagram correct for my code?

I am trying hard to achieve expected output, but failing to create a reusable code for below problem statement. Any suggestions?

Problem when I am trying to load txt in Jupyter Notebook

zsh shell problem specifically when I am trying to get output

I am trying to better understand recursion by using the FizzBuzz problem in javascript

I am trying to make a for loop with a if statement in it to find a specific name in an arraylist

I am trying to find the last digit of partial sum of fibonacci series

I am trying to find the maximum occurrences of a string in a list using Python

I am trying to find the scrabble value of a word using C program

I am trying to do a find for folders begining with "of" and get their folder sizes