'scraping console commands for a videogame from a website
im trying to scrape some data from a website. im basically trying to scrape some "console commands" for the video game counter strike global offensive. and im trying to scrape these commands from a pro player settings website. i already made it work before but the website underwent some changes so it rendered my old script obsolete. i am basically trying to parse the commands to a file so they can be executed in game.
for example: cl_crosshairstyle 1; viewmodel_recoil 0 <- if pasted into the games console, this will work. the website provides this format when you click the "copy to clipboard" button. unfortunately for me, i dont know how to parse that data. the code below manages to parse the values of commands i need but the names are stored in a "data-field" thingy. i personally have no experience with websites or html/php/css ( c++ and a bit of python ). any help is appreciated!
source = requests.get("https://prosettings.net/players/niko/").text
soup = BeautifulSoup(source, "lxml")
div = soup.find("div")
crosshair = div.find(id = "csgo_crosshair")
viewmodel = div.find(id = "csgo_viewmodel")
bob = div.find(id = "csgo_bob")
UPDATE:
i have solved my problem. im really not proud of the way i achieved it but whatever, here it is:
def kek(source):
soup = BeautifulSoup(source, "lxml")
div = soup.find("div")
crosshair = div.find(id = "csgo_crosshair")
viewmodel = div.find(id = "csgo_viewmodel")
bob = div.find(id = "csgo_bob")
commands = []
crosshaircmd = crosshair.find_all(attrs = {"class" : "format-number"})
bobcmd = bob.find_all(attrs = {"class" : "format-number"})
viewmodelcmd = viewmodel.find_all(attrs = {"class" : "format-number"})
bobvalues = bob.find_all("dd")
crosshairvalues = crosshair.find_all("dd")
viewmodelvalues = viewmodel.find_all("dd")
for k, i in enumerate(bobcmd):
cmd1 = i.get("data-field") + " " + bobvalues[k].text + ";"
commands.append(cmd1)
for l, j in enumerate(viewmodelcmd):
cmd2 = j.get("data-field") + " " + viewmodelvalues[l].text + ";"
commands.append(cmd2)
for x, y in enumerate(crosshaircmd):
cmd3 = y.get("data-field") + " " + crosshairvalues[x].text + ";"
commands.append(cmd3)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
