Home>

As planned, you need to get the result like this, a list with the following hero values ​​on the page:

name: "Hero name"

dis: "Hero disadvantaged"

name is written to

disadvantage is written to data-value

Here is the whole html:

<td class="cell-icon" data-value="Outworld Destroyer"><div class="image-container image-container-hero image-container-icon"><a href="/heroes/outworld-destroyer"><img class="image-hero image-icon" data-tooltip-url="/heroes/outworld-destroyer/tooltip" rel="tooltip-remote" src="/assets/heroes/outworld-destroyer-60496afd5b92709cbc2350ddd2257b1d6f0e1ce6dd5b2c6a4614e9ace6d29 title="Outworld Destroyer"/></a></div></td>, <td class="cell-xlarge"><a class="link-type-hero" href="/heroes/outworld-destroyer">Outworld Destroyer</a></td>, <td data-value="2.9031">2.90%<div class="bar bar-default"><div class="segment segment-disadvantage" style="width: 100.00000000000001%;"></div></div></td>, <td data-value="46.0201">46.02%<div class="bar bar-default"><div class="segment segment-win" style="width: 76.92954492645572%;"></div></div></td>, <td data-value="53896">53.896<div class="bar bar-default"><div class="segment segment-match" style="width: 46.159643713600545%;"></div></div></td>

URL= 'https://en.dotabuff.com/heroes/abaddon/counters' It turns out to display only 1 name and that's it.

This is the output:

[{'name': 'Outworld Destroyer'}]

Here is my "code":

def get_html(url, params=None):
    r= requests.get(url, headers=HEADERS, params=params)
    return r
def get_content(html):
    soup= BeautifulSoup(html, 'lxml')
    items= soup.find_all('table', class_='sortable')
    heroes= []
    for item in items:
        td= item.td['data-value']
        heroes.append({
            'name': item.td['data-value']
        })
        print(heroes)
def parse():
    html= get_html(URL)
    if html.status_code== 200:
        get_content(html.text)
    else:
        print("error")

I'm inexperienced myself, but I can't find a solution in the guides.

What headers are you sending?

Александр2022-01-26 07:54:12
  • Answer # 1
    items= soup.find('table', class_='sortable').find_all('tr')[1:]