File size: 1,570 Bytes
aade47a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-


def get_lyrics(inp):
    
    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    from bs4 import BeautifulSoup
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--disable-dev-shm-usage")
    chrome_options.add_argument("--no-sandbox")
    driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), options=chrome_options)

    #driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
    browser = webdriver.Chrome(
        executable_path="C:\Users\User\Desktop\PROGRAM_FILES\chromedriver.exe")
    
    lyrics_text=[]
    strung_together=''.join(inp.split(' '))
    initial="https://www.google.com/search?q="
    str_=f"{initial}{strung_together}+lyrics&oq="
    
    browser.get(str_) 
    src = browser.page_source
    soup = BeautifulSoup(src, 'lxml')
    
    lyrics_soup = soup.find_all('div', {'class': 'ujudUb'})
    for span_tags in lyrics_soup:
        span_content=soup.find_all('span', {'jsname': 'YS01Ge'})
        for embedded_lyrics in span_content:
            lyrics_text.append(embedded_lyrics.get_text())
    
    
    return lyrics_text


def ask_inp(inputfromuser):
    #song_inf=str(input("Enter artist name and song name space separated: "))    
    return get_lyrics(inputfromuser)

if __name__=='__main__':
    ask_inp()