Sono un po 'novizio di programmazione e ho cercato di raschiare i testi di Andre 3000 al genio Rap, http://genius.com/artists/Andre-3000, usando Beautiful Soup (Una libreria Python per estrarre i dati da File HTML e XML). Il mio obiettivo finale è avere i dati in un formato stringa. Ecco cosa ho finora:Testo di Web Scraping Rap su Rap Genius w/Python
from bs4 import BeautifulSoup
from urllib2 import urlopen
artist_url = "http://rapgenius.com/artists/Andre-3000"
def get_song_links(url):
html = urlopen(url).read()
# print html
soup = BeautifulSoup(html, "lxml")
container = soup.find("div", "container")
song_links = [BASE_URL + dd.a["href"] for dd in container.findAll("dd")]
print song_links
get_song_links(artist_url)
for link in soup.find_all('a'):
print(link.get('href'))
Quindi ho bisogno di aiuto con il resto del codice. Come faccio a ottenere i suoi testi in formato stringa? e poi come uso il kit di strumenti della lingua nazionale (nltk) per inviare token alle frasi e alle parole.
questo è grande, ma ottengo questo errore quando provo a farlo funzionare "ImportError: No module named BS4" – Ibrewster
@Ibrewster è necessario installare 'beautifulsoup4': run 'pip installa beautifulsoup4'. – alecxe
sì, avevo già installato bs4 e non funzionava. così ho provato a reinstallarlo e ancora non funziona. – Ibrewster