Python 2.7/Selenium 2 AttributeError: 'NoneType' object has no attribute 'group' -
i new python/selenium , have been ceaselessly trying resolve issue code i'd modify no luck. after researching on internet , trying various changes days, i'm @ wits end , hoping here help. apologize in advance if of terminology use misguided or incorrect. if need additional information, please let me know.
specifically, run script automate torrent downloading / transcoding / re-uploading. 1 issue in particular i'm having trouble follows:
the script written in python , relies on elements of selenium , transmission daemon/remote function. once has navigated website , chosen torrent download, pulls information page using xpaths. i'm not sure if it's part of code or following causing break, when there no release date , / or additional info listed script stops running , returns error.
traceback (most recent call last): file "main.py", line 30, in <module> flac, missing, date, media_type, ul_page, cat_num, rel_type, seeders = get_torrent.get_available(driver) file "/home//desktop/get_torrent.py", line 38, in get_available release_date = re.search('\d{4}-\d{2}-\d{2}', additional_info).group(0) attributeerror: 'nonetype' object has no attribute 'group'
from can tell, either:
the website doesn't have info stored in additional_info being set none doesn't have group 0 attribute, or...
the additional_info not contain re.search query causing error.
either way, i'd this. if (whatever causing error; i.e. additional_info blank, re.search reference doesn't exist, etc.) true, skip trying store re.search('\d...) release_date , instead restart torrent search process find 1 doesn't have issue. (you can't re-upload torrent doesn't have release date aren't viable options).
code snippet in question:
additional_info = driver.find_element_by_xpath("//tr[@class='edition_info'][last()]/td").text release_date = re.search('\d{4}-\d{2}-\d{2}', additional_info).group(0) catalog_num = re.search('[a-z]+-[0-9]+', additional_info.split('/')[-2:-1][0])
the common pattern handle situations when there no match is:
additional_info = driver.find_element_by_xpath("//tr[@class='edition_info'][last()]/td").text match = re.search(r'\d{4}-\d{2}-\d{2}', additional_info) if match: release_date = match.group(0)
or, may set release_date
default value, none
instance:
release_date = match.group(0) if match else none
also, here relevant discussion:
Comments
Post a Comment