I am fairly new to Python myself. For training purposes, I am trying to scrape some data from a website. Digging through the HTML/CSS of said website taught me that it isn't that simple because most div's etc don't have a class or ID.
<table class="trade-list-table max-width">
<thead>
</thead>
<tbody>
<tr class="cursor-pointer" data-on-click-link="/pc/Trade/Detail/313809613" data-on-click-link-action="NewWindow" data-toggle="tooltip" data-original-title="" title="">
<td>
<img class="trade-item-icon item-quality-legendary" alt="Icon" src="./Search Result - Tamriel Trade Centre_files/crafting_outfitter_potion_014.png" data-original-title="" title="">
<div class="item-quality-legendary">
XXSTRING1XX
</div>
<div>
Level:
<img class="small-icon" src="./Search Result - Tamriel Trade Centre_files/nonvet.png">
XXSTRING2XX
</div>
</td>
<td class="hidden-xs">
<div class="text-small-width text-danger">
XXSTRING3XX
</div>
</td>
<td class="hidden-xs">
<div>
XXSTRING4XX
</div>
<div>
XXSTRING5XX
</div>
</td>
<td class="gold-amount bold">
<img class="small-icon" src="./Search Result - Tamriel Trade Centre_files/gold.png">
XXSTRING6XX
<div class="text-danger">
X
</div>
<img class="small-icon" src="./Search Result - Tamriel Trade Centre_files/amount.png">
XXSTRING7XX
<div class="text-danger">
=
</div>
<img class="small-icon" src="./Search Result - Tamriel Trade Centre_files/gold.png">
54,999
</td>
<td class="bold hidden-xs" data-mins-elapsed="2">Now</td>
</tr>
I tried many things. I've been struggling for the past 7 days. When I print the result I need XXSTRING1XX until XXSTRING7XX so that I can push them into a .csv file or something similar.
The difficulty I've been having is that most div's don't have a specific class. And in most cases, I am unable to return a string.
I've been using Python with Requests and BeautifulSoup from bs4.
import requests
from bs4 import BeautifulSoup
page = requests.get('https://eu.tamrieltradecentre.com/pc/Trade/SearchResult?ItemID=211&SearchType=Sell&ItemNamePattern=Dreugh+Wax&ItemCategory1ID=&ItemCategory2ID=&ItemCategory3ID=&ItemTraitID=&ItemQualityID=&IsChampionPoint=false&LevelMin=&LevelMax=&MasterWritVoucherMin=&MasterWritVoucherMax=&AmountMin=&AmountMax=&PriceMin=&PriceMax=')
soup = BeautifulSoup(page.content, 'html.parser')
container = soup.find(class_="trade-list-table max-width")
itembox = container.find_all(class_="cursor-pointer")
item = itembox[0]
# Select all table rows and first TD
tr = container.find_all(class_="cursor-pointer")
tr1 = tr[0].find_all('td')
# Itemname
itemname = item.find('div', class_="item-quality-legendary").get_text()
print (itemname)
# Itemlevel + level type
# Tradername
# Location
# Guild name
# Unit price
# Quantity
# Total price
# Timestamp?