前提・実現したいこと
抽選サイトで抽選可能なものに申し込みを自動で行うシステムを作りたいと思っています。
抽選できるものには申し込みボタンがあり、自動で申し込みボタンを見つけ、クリックするシステムを組みたいと思っています。
1か所につき申し込みは一度まで、常に抽選があるのではなく、抽選がない場合には「不可」を出力され、システムを閉じるようにしたいです。
現在のシステムでは"不可"は出力され、サイトは閉じます。しかし、以下のようなエラーメッセージが出てしま
pythonのseleniumを使い、途中でつまずいてしまったため、解決方法をご教授いただきたいです。
発生している問題・エラーメッセージ
ERROR:root:Internal Python error in the inspect module. Below is the traceback from this internal error. Traceback (most recent call last): File "<ipython-input-104-ec29e3e3dcb7>", line 3, in <module> element = browser.find_element_by_xpath('//img[@alt=\"申込\"]') File "C:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element return self.execute(Command.FIND_ELEMENT, { File "C:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//img[@alt="申込"]"} (Session info: chrome=93.0.4577.82) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3437, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-104-ec29e3e3dcb7>", line 7, in <module> sys.exit() SystemExit During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\anaconda\lib\site-packages\IPython\core\ultratb.py", line 1101, in get_records return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset) File "C:\anaconda\lib\site-packages\IPython\core\ultratb.py", line 248, in wrapped return f(*args, **kwargs) File "C:\anaconda\lib\site-packages\IPython\core\ultratb.py", line 281, in _fixed_getinnerframes records = fix_frame_records_filenames(inspect.getinnerframes(etb, context)) File "C:\anaconda\lib\inspect.py", line 1515, in getinnerframes frameinfo = (tb.tb_frame,) + getframeinfo(tb, context) AttributeError: 'tuple' object has no attribute 'tb_frame' --------------------------------------------------------------------------- NoSuchElementException Traceback (most recent call last) <ipython-input-104-ec29e3e3dcb7> in <module> 2 try: ----> 3 element = browser.find_element_by_xpath('//img[@alt=\"申込\"]') 4 except: C:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py in find_element_by_xpath(self, xpath) 393 """ --> 394 return self.find_element(by=By.XPATH, value=xpath) 395 C:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py in find_element(self, by, value) 975 value = '[name="%s"]' % value --> 976 return self.execute(Command.FIND_ELEMENT, { 977 'using': by, C:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params) 320 if response: --> 321 self.error_handler.check_response(response) 322 response['value'] = self._unwrap_value( C:\anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response) 241 raise exception_class(message, screen, stacktrace, alert_text) --> 242 raise exception_class(message, screen, stacktrace) 243 NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//img[@alt="申込"]"} (Session info: chrome=93.0.4577.82) During handling of the above exception, another exception occurred: SystemExit Traceback (most recent call last) [... skipping hidden 1 frame] <ipython-input-104-ec29e3e3dcb7> in <module> 6 browser.quit() ----> 7 sys.exit() SystemExit: During handling of the above exception, another exception occurred: TypeError Traceback (most recent call last) [... skipping hidden 1 frame] C:\anaconda\lib\site-packages\IPython\core\interactiveshell.py in showtraceback(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code) 2052 stb = ['An exception has occurred, use %tb to see ' 2053 'the full traceback.\n'] -> 2054 stb.extend(self.InteractiveTB.get_exception_only(etype, 2055 value)) 2056 else: C:\anaconda\lib\site-packages\IPython\core\ultratb.py in get_exception_only(self, etype, value) 752 value : exception value 753 """ --> 754 return ListTB.structured_traceback(self, etype, value) 755 756 def show_exception_only(self, etype, evalue): C:\anaconda\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self, etype, evalue, etb, tb_offset, context) 627 chained_exceptions_tb_offset = 0 628 out_list = ( --> 629 self.structured_traceback( 630 etype, evalue, (etb, chained_exc_ids), 631 chained_exceptions_tb_offset, context) C:\anaconda\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context) 1365 else: 1366 self.tb = tb -> 1367 return FormattedTB.structured_traceback( 1368 self, etype, value, tb, tb_offset, number_of_lines_of_context) 1369 C:\anaconda\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context) 1265 if mode in self.verbose_modes: 1266 # Verbose modes need a full traceback -> 1267 return VerboseTB.structured_traceback( 1268 self, etype, value, tb, tb_offset, number_of_lines_of_context 1269 ) C:\anaconda\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self, etype, evalue, etb, tb_offset, number_of_lines_of_context) 1122 """Return a nice text document describing the traceback.""" 1123 -> 1124 formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context, 1125 tb_offset) 1126 C:\anaconda\lib\site-packages\IPython\core\ultratb.py in format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset) 1080 1081 -> 1082 last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records) 1083 1084 frames = self.format_records(records, last_unique, recursion_repeat) C:\anaconda\lib\site-packages\IPython\core\ultratb.py in find_recursion(etype, value, records) 380 # first frame (from in to out) that looks different. 381 if not is_recursion_error(etype, value, records): --> 382 return len(records), 0 383 384 # Select filename, lineno, func_name to track frames with TypeError: object of type 'NoneType' has no len()
該当のソースコード
python element = None try: element = browser.find_element_by_xpath('//img[@alt=\"申込\"]') except: print('不可') browser.quit() sys.exit()
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー