Home > Blockchain >  how to get the value of a specific column of each row in a html table?
how to get the value of a specific column of each row in a html table?

Time:05-14

so basically in the site listed below; I need to get the sensitivity (7th column) of each setting (row)

site: https://prosettings.net/cs-go-pro-settings-gear-list/

table id: "table_1"

2 rows class: "even", "odd"

sensitivity class: " numdata float column-sensitivity"

i made this, but it just prints None (i'm newbie to programming lol)

import requests
from bs4 import BeautifulSoup

site = "https://prosettings.net/cs-go-pro-settings-gear-list/"
r = requests.get(site)
soup = BeautifulSoup(r. text, "html.parser")
settings_table = soup.find("table", id="table_1")

for settings in settings_table.find_all("tbody"):
    rows = settings.find_all("tr")

    for row in rows:
        sens = row.find("td", class_=" numdata float  column sensitivity")
            print(sens)

CodePudding user response:

The data comes from a POST request.

Here's how to get the seventh row, which is, sensitivity:

import requests

api_url = "https://prosettings.net/wp-admin/admin-ajax.php?action=get_wdtable&table_id=55"

headers = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:100.0) Gecko/20100101 Firefox/100.0",
    "X-Requested-With": "XMLHttpRequest",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "Referer": "https://prosettings.net/cs-go-pro-settings-gear-list/",
}

payload = "draw=1&columns[0][data]=0&columns[0][name]=rank&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=1&columns[1][name]=team&columns[1][searchable]=true&columns[1][orderable]=true&columns[1][search][value]=&columns[1][search][regex]=false&columns[2][data]=2&columns[2][name]=player&columns[2][searchable]=true&columns[2][orderable]=true&columns[2][search][value]=&columns[2][search][regex]=false&columns[3][data]=3&columns[3][name]=role&columns[3][searchable]=true&columns[3][orderable]=true&columns[3][search][value]=&columns[3][search][regex]=false&columns[4][data]=4&columns[4][name]=mouse&columns[4][searchable]=true&columns[4][orderable]=true&columns[4][search][value]=&columns[4][search][regex]=false&columns[5][data]=5&columns[5][name]=hz&columns[5][searchable]=true&columns[5][orderable]=true&columns[5][search][value]=&columns[5][search][regex]=false&columns[6][data]=6&columns[6][name]=dpi&columns[6][searchable]=true&columns[6][orderable]=true&columns[6][search][value]=&columns[6][search][regex]=false&columns[7][data]=7&columns[7][name]=sensitivity&columns[7][searchable]=true&columns[7][orderable]=true&columns[7][search][value]=&columns[7][search][regex]=false&columns[8][data]=8&columns[8][name]=edpi&columns[8][searchable]=true&columns[8][orderable]=true&columns[8][search][value]=&columns[8][search][regex]=false&columns[9][data]=9&columns[9][name]=zoomsens&columns[9][searchable]=true&columns[9][orderable]=true&columns[9][search][value]=&columns[9][search][regex]=false&columns[10][data]=10&columns[10][name]=mouseaccel&columns[10][searchable]=true&columns[10][orderable]=true&columns[10][search][value]=&columns[10][search][regex]=false&columns[11][data]=11&columns[11][name]=windowssens&columns[11][searchable]=true&columns[11][orderable]=true&columns[11][search][value]=&columns[11][search][regex]=false&columns[12][data]=12&columns[12][name]=rawinput&columns[12][searchable]=true&columns[12][orderable]=true&columns[12][search][value]=&columns[12][search][regex]=false&columns[13][data]=13&columns[13][name]=monitor&columns[13][searchable]=true&columns[13][orderable]=true&columns[13][search][value]=&columns[13][search][regex]=false&columns[14][data]=14&columns[14][name]=hz_1&columns[14][searchable]=true&columns[14][orderable]=true&columns[14][search][value]=&columns[14][search][regex]=false&columns[15][data]=15&columns[15][name]=gpu&columns[15][searchable]=true&columns[15][orderable]=true&columns[15][search][value]=&columns[15][search][regex]=false&columns[16][data]=16&columns[16][name]=resolution&columns[16][searchable]=true&columns[16][orderable]=true&columns[16][search][value]=&columns[16][search][regex]=false&columns[17][data]=17&columns[17][name]=aspectratio&columns[17][searchable]=true&columns[17][orderable]=true&columns[17][search][value]=&columns[17][search][regex]=false&columns[18][data]=18&columns[18][name]=scalingmode&columns[18][searchable]=true&columns[18][orderable]=true&columns[18][search][value]=&columns[18][search][regex]=false&columns[19][data]=19&columns[19][name]=mousepad&columns[19][searchable]=true&columns[19][orderable]=true&columns[19][search][value]=&columns[19][search][regex]=false&columns[20][data]=20&columns[20][name]=keyboard&columns[20][searchable]=true&columns[20][orderable]=true&columns[20][search][value]=&columns[20][search][regex]=false&columns[21][data]=21&columns[21][name]=headset&columns[21][searchable]=true&columns[21][orderable]=true&columns[21][search][value]=&columns[21][search][regex]=false&columns[22][data]=22&columns[22][name]=cfgcrosshair&columns[22][searchable]=true&columns[22][orderable]=true&columns[22][search][value]=&columns[22][search][regex]=false&order[0][column]=0&order[0][dir]=asc&start=0&length=-1&search[value]=&search[regex]=false&wdtNonce=415443b358"

data = requests.post(api_url, headers=headers, data=payload).json()["data"]
row_seven = [item[7] for item in data]
print("\n".join(row_seven))

Output:

1.45
2.20
3.09
0.90
1.42
1.70
1.60
1.65
1.40
1.90
1.77
1.50

and a lot more ...
  • Related