I'd like a way to generate a filename for osu! beatmaps which I'm downloading. Ideally I would go through the HTML looking for a certain phrase, beatmapsets?q=, and get the word(s) that come after the q=.
I've tried using lxml.html, however I have little experience in it, and in the code below, it returns an empty list.
class OsuMaps:
def generateFileName(self, num1=None):
if not num1:
print("Missing required argument: 'num1'")
return
dl = requests.get(f"https://bloodcat.com/osu/s/{num1.rstrip()}")
# ..generate FinalName
tree = fromstring(dl.content)
FinalName = tree.xpath(
"//a[contains(@href='beatmapsets?q=')]"
)
return FinalName
osu - OsuMaps()
osu.generateFileName("653534") # ideal outcome - "653534 Panda Eyes - ILY"
The ideal result is commented in, however I don't know where to start. All I know is the two keywords [that being the songname, ILY, and artist, Panda Eyes] I need are in the HTML as:
<a class="beatmapset-header__details-text beatmapset-header__details-text--title u-ellipsis-overflow" href="/beatmapsets?q=ILY">ILY</a>
and
<a class="beatmapset-header__details-text beatmapset-header__details-text--artist" href="/beatmapsets?q=Panda%20Eyes">Panda Eyes</a>
I would also need to be able to re-use this code so that it gets q=<text> text every time.
https://bloodcat.com/osu/s/653534will prompt to download the file653534 Panda Eyes - ILY.osz- it's not html content.len(dl.text)-->9123471The question is not relevantgenerateFilename()function?