Python BeautifulSoup Looping Through Table Data

Python BeautifulSoup Looping Through Table Data

Very new to Python here. I'm trying to capture some data from this page&nbsp;<a href="https://us.diablo3.com/en/item/helm/" target="_blank" style="color: rgb(0, 89, 153);">this page</a>. I'm trying to get the item name and the item type captured in two lists. I can figure out how to join them into one table later. Any help would be great!

Very new to Python here. I'm trying to capture some data from this page this page. I'm trying to get the item name and the item type captured in two lists. I can figure out how to join them into one table later. Any help would be great!

The lines of code work on their own but the loop doesn't work for me. This produces two lines of code successfully:

import urllib
import bs4 as bs

sauce = urllib.request.urlopen('https://us.diablo3.com/en/item/helm/').read() soup = bs.BeautifulSoup(sauce, 'lxml')

item_details = soup.find('tbody') print(item_details)

item_name = item_details.find('div', class_='item-details').h3.a.text print(item_name)

item_type = item_details.find('ul', class_='item-type').span.text print(item_type)

This repeats the value of the first item_name over and over:

for div in soup.find_all('div', class_='item-details'):
    item_name = item_details.find('div', class_='item-details').h3.a.text
    print(item_name)
    item_type = item_details.find('ul', class_='item-type').span.text
    print(item_type)

This is the output:

Veil of Steel
Magic Helm
Veil of Steel
Magic Helm
Veil of Steel
Magic Helm
Veil of Steel
Magic Helm
Veil of Steel
Magic Helm
Veil of Steel
Magic Helm
Veil of Steel
Magic Helm
...


python

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Hire Python Developers

Are you looking for experienced, reliable, and qualified Python developers? If yes, you have reached the right place. At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, our full-stack Python development services...

Top Python Development Companies | Hire Python Developers

After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...

Python Hello World Program - Create & Run Your First Python Program in PyCharm

Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.

Standard Data Types in Python - Python Tutorial - Python Training

This video on 'Standard Data Types in Python' will help you establish a foothold on Python by helping you learn basic concepts.