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
...