Note that there are some explanatory texts on larger screens.

plurals
  1. POCatch Exception , Run Alternative Code & Continue from Line Python
    primarykey
    data
    text
    <p>I'm currently using Selenium &amp; BeautifulSoup to extract data , sometimes the format for different pages might be slightly different, at most max 3 different type of html difference, when it came to one of the different page, i couldn't help it as it gave me an exception because the data isnt there.</p> <p><strong>Can i do something like if Exception = AttributeError, try this code and continue from where it stopped?</strong></p> <pre><code>AttributeError: 'NoneType' object has no attribute 'text' </code></pre> <p>This is the current code </p> <pre><code> price = soup.find('li', {'id' :'J_PromoPrice'}) priced = price.find('strong', {'class' :'tb-rmb-num'}).text if priced == "": priced = price.find('strong', {'class' :'tb-rmb-num'}).text else: print ("No Normal Price Found") </code></pre> <p>As you can see , there is already a set of IF ELSE to detect if it's empty , if empty = find another tag for text that will handle 2 different type of html but the 3rd one which i'm facing an issue is that it doesn't even have the TAG but it does have it somewhere else.</p> <p>In short, i'm trying to Grab text from somewhere else if i hit this exception then continue the script from where the exception was slapped in my face.</p> <p>Update Full Trace</p> <pre><code>Traceback (most recent call last): File "C:\Users\X\Desktop\Python\python.py", line 521, in &lt;module&gt; getLoadItem() File "C:\Users\X\Desktop\Python\python.py", line 57, in getLoadItem getLoadItemAnalyse(loop['ID'],loop['Link']) File "C:\Users\X\Desktop\Python\python.py", line 236, in getLoadItemAnalyse priced = price.find('strong', {'class' :'tb-rmb-num'}).text AttributeError: 'NoneType' object has no attribute 'text' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload