python function returns nothing

Miguel 2488

I'm writting a function that sould be able to scrap links from people names contained in an html file. I wanna warn you all beforehand, i know it's ugly, i know it's long, and i also know it's certainly not the most elegant way of doing it. But this is the best i could come up with, since i'm a total beginner in python.

Here's my code:

file = 'C:/users/me/webpage.html'

def get_links(file):
    import codecs
    from bs4 import BeautifulSoup as bs
    f = codecs.open(filename, 'r', 'utf-8')
    soup = bs(f.read(),'lxml')
    link_list = []
    A_list = soup.find(string = 'Rob Agerbeek').find_parent('ul').find_all(title = ['Rob Agerbeek', 'Albert Ammons', 'Andrews Sisters', 'Winifred Atwell'])
    A_links = [i.get('href') for i in A_list]
    link_list += A_links
    B_list = soup.find(string = 'Bob Baldori').find_parent('ul').find_all(title = ['Bob Baldori', 'Marcia Ball', 'Deanna Bogart', 'James Booker', 'Eden Brent', 'Dave Brubeck'])
    B_links = [i.get('href') for i in B_list]
    link_list += B_links
    C_list = soup.find(string = 'Francis Craig').find_parent('ul').find_all(title = ['Commander Cody and His Lost Planet Airmen', 'Francis Craig', 'James Crutchfield', 'Ray Charles'])
    C_links = [i.get('href') for i in C_list]
    link_list += C_links
    D_list = soup.find(string = 'Francis Craig').find_parent('ul').find_all(title = ['Caroline Dahl', 'Cow Cow Davenport', 'Blind John Davis', 'Neville Dickie', 'Fats Domino', 'Floyd Domino', 'Dorothy Donegan', 'Georgia Tom Dorsey', 'Dr. John', 'Champion Jack Dupree', 'Big Joe Duskin'])
    D_links = [i.get('href') for i in D_list]
    link_list +=D_links
    E_list = soup.find(string = 'William Ezell').find_parent('ul').find_all(title = ['William Ezell'])
    E_links = [i.get('href') for i in E_list]
    link_list += E_links
    F_list = soup.find(string = 'Wayne Federman').find_parent('ul').find_all(title = ['Wayne Federman', 'Ella Fitzgerald', 'Frankie Ford', 'Ernie Freeman', 'Keith Emerson'])
    F_links = [i.get('href') for i in F_list]
    link_list +=F_links
    G_list = soup.find(string = 'Blind Leroy Garnett').find_parent('ul').find_all(title = ['Blind Leroy Garnett', 'Harry Gibson', 'Harry Gibson'])
    G_links = [i.get('href') for i in G_list]
    link_list +=G_links
    H_list = soup.find(string = 'Willie Hall').find_parent('ul').find_all(title = ['Willie Hall', 'Jools Holland', 'Camille Howard', 'Bob Hall', 'Henri Herbert', 'John Lee Hooker', 'Nicky Hopkins'])
    H_links = [i.get('href') for i in H_list]
    link_list += H_links
    J_list = soup.find(string = 'Elton John').find_parent('ul').find_all(title = ['Elton John', 'Pete Johnson', 'Louis Jordan'])
    J_links = [i.get('href') for i in J_list]
    link_list += J_links
    K_list = soup.find(string = 'Michael Kaeshammer').find_parent('ul').find_all(title = ['Michael Kaeshammer', 'Shizuko Kasagi', 'Joe Krown'])
    K_links = [i.get('href') for i in K_list]
    link_list += K_links
    L_list = soup.find(string = 'Booker T. Laury').find_parent('ul').find_all(title = ['Booker T. Laury', 'Jerry Lee Lewis', 'Meade Lux Lewis', 'Liberace', 'Little Richard', 'Little Willie Littlefield', 'Cripple Clarence Lofton', 'Professor Longhair'])
    L_links = [i.get('href') for i in L_list]
    link_list += L_links
    M_list = soup.find(string = 'Memphis Slim').find_parent('ul').find_all(title = ['Memphis Slim', 'Big Maceo Merriweather', 'Moon Mullican'])
    M_links = [i.get('href') for i in M_list]
    link_list += M_links
    N_list = soup.find(string = 'Romeo Nelson').find_parent('ul').find_all(title = ['Romeo Nelson', 'Charlie Norman'])
    N_links = [i.get('href') for i in N_list]
    link_list += N_links
    P_list = soup.find(string = 'Bill Payne').find_parent('ul').find_all(title = ['Bill Payne', 'Oscar Peterson', 'Piano Red', 'Pinetop Perkins', 'Ross Petot', 'Sammy Price', 'Professor Longhair'])
    P_links = [i.get('href') for i in P_list]
    link_list += P_links
    R_list = soup.find(string = 'Boogie Woogie Red').find_parent('ul').find_all(title = ['Boogie Woogie Red', 'Maurice Rocco', 'Walter Roland', 'Leon Russell'])
    R_links = [i.get('href') for i in R_list]
    link_list += R_links
    S_list = soup.find(string = 'Ulf Sandström').find_parent('ul').find_all(title = ['Ulf Sandström', 'Bob Seeley', 'Luca Sestak', 'Omar Shariff', 'Robert Shaw', 'Freddie Slack', 'Huey "Piano" Smith', 'Clarence "Pine Top" Smith', 'Charlie Spand', 'Otis Spann', 'Speckled Red', 'Roosevelt Sykes'])
    S_links = [i.get('href') for i in S_list]
    link_list += S_links
    T_list = soup.find(string = 'Gene Taylor').find_parent('ul').find_all(title = ['Gene Taylor', 'Montana Taylor', 'George W. Thomas', 'Hersal Thomas', 'Allen Toussaint', 'T. Rex', 'Stephanie Trick', 'Big Joe Turner', 'Ike Turner'])
    T_links = [i.get('href') for i in T_list]
    link_list += T_links
    W_list = soup.find(string = 'Rick Wakeman').find_parent('ul').find_all(title = ['Rick Wakeman', 'Tuts Washington', 'Kenny "Blues Boss" Wayne', 'Vince Weber', 'Robert Wells', 'Clarence Williams', 'Jabo Williams', 'Mitch Woods'])
    W_links = [i.get('href') for i in W_list]
    link_list += W_links
    Y_list = soup.find(string = 'Jimmy Yancey').find_parent('ul').find_all(title = ['Jimmy Yancey'])
    Y_links = [i.get('href') for i in Y_list]
    link_list += Y_links
    Z_list = soup.find(string = 'Silvan Zingg').find_parent('ul').find_all(title = ['Silvan Zingg', 'Axel Zwingenberger', 'ZZ Top'])
    Z_links = [i.get('href') for i in Z_list]
    link_list += Z_links

    return link_list

The main issue here is that every line works independently, i'm getting the desired output with this code, however when i wanna run it inro a function, it returns nothing, no error, no None, just nothing, absolutely no result, just a blank output. I would highly appreciate if someone could shine a light for me here.

Thank you all

AlephRZS

Since your function returns the correct value, probably there is a fault in the way you pass this value to the other function. A way would be to make another variable. Or just pass the method itself.

otherFunction(get_links(file)) 

Or

link = get_links(file)
otherFunction(link)

Might not be it but return and local variables gave me a hard time when I was learning so I guess worth mentioning.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Return function returns nothing

How to create function that returns nothing

Why XMPP function returns nothing?

Laravel hasmany function returns nothing

Function that only returns false returns nothing

python - sql query returns nothing

Selector returns nothing in scrapy for python

Reading the file returns nothing (python)

Non-void function returns nothing dart

ANY function returns nothing when the database is empty

Replace function $$find always returns nothing

Callback function for database query returns nothing

Google spreadsheet custom function returns nothing

Async function to get JSON returns nothing

if function in javascript returns nothing..why?

For loop returns nothing when using function

How do you get to the value inside of a python function that returns nothing for unit testing?

Function to return the index at which a specific letter occurs always returns nothing regardless of input in Python?

Python Scrapy spider is crawling the url, but returns nothing

python dynamodb, scripts returns empty and does nothing

Function output displaying nothing, Python

Nothing is output in python recursive function

Function returns nothing embedded in html, while working in console

Create a completion block that returns nothing but executes another function when completed?

return function in another child class from the same parent returns nothing

onBeforeUnload creates prompt even when function returns nothing

Function returns nothing rather than the expected value "None"

Test if function returns nothing powershell and return "No Results found"

How do you check if your function returns nothing?