'Need assistance with scrapping data from table whose fields are not similar for other pages [selenium, python]

I have a table on all pages on which some pages has a field let's call it

<tr><td>Sample Field Beta</td><td>Some Value Alpha</td></tr>
<tr><td>Sample Field Beta</td><td>Some Value Beta</td></tr>
<tr><td>Sample Field Beta</td><td>Some Value Gamma</td></tr>
<tr><td>Sample Field Beta</td><td>Some Value Delta</td></tr>

Suppose the xpath for these table rows are -

//*[@id="stock_info"]/div[1]/div/table/tbody/tr[1]

//*[@id="stock_info"]/div[1]/div/table/tbody/tr[2]

//*[@id="stock_info"]/div[1]/div/table/tbody/tr[3]

//*[@id="stock_info"]/div[1]/div/table/tbody/tr[4]

For some other page suppose beta is not present which also changes the right serial for my xpaths.

<tr><td>Sample Field Beta</td><td>Some Value Alpha</td></tr>
<tr><td>Sample Field Beta</td><td>Some Value Gamma</td></tr>
<tr><td>Sample Field Beta</td><td>Some Value Delta</td></tr>

How should I scrape the Gamma and Delta in such case? Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source