質問編集履歴
3
コードの修正
    
        title	
    CHANGED
    
    | 
            File without changes
         | 
    
        body	
    CHANGED
    
    | @@ -25,16 +25,16 @@ | |
| 25 25 |  | 
| 26 26 | 
             
                scraping_count = 0 #確認用変数
         | 
| 27 27 | 
             
                while page_number <= page_number_max:
         | 
| 28 | 
            -
                    class_group = driver.find_elements_by_class_name("rc") | 
| 28 | 
            +
                    class_group = driver.find_elements_by_class_name("rc")
         | 
| 29 29 | 
             
                    for class_name in class_group:
         | 
| 30 | 
            -
                        title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md"))
         | 
| 30 | 
            +
                        title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md").text)
         | 
| 31 31 | 
             
                        url_list.append(class_name.find_element_by_tag_name("a").get_attribute("href"))
         | 
| 32 32 | 
             
                        scraping_count += 1
         | 
| 33 33 |  | 
| 34 | 
            -
                    if driver. | 
| 34 | 
            +
                    if driver.find_elements_by_id("pnnext") == []: #次のページがなかったらループを抜け出す
         | 
| 35 35 | 
             
                        page_number = page_number_max + 1
         | 
| 36 36 | 
             
                    else:
         | 
| 37 | 
            -
                        next_page = driver. | 
| 37 | 
            +
                        next_page = driver.find_elements_by_id("pnnext").get_attribute("href")
         | 
| 38 38 | 
             
                        driver.get(next_page)
         | 
| 39 39 | 
             
                        page_number += 1
         | 
| 40 40 | 
             
                        time.sleep(3)
         | 
| @@ -70,13 +70,13 @@ | |
| 70 70 | 
             
            ```
         | 
| 71 71 | 
             
            実行すると以下のように出力されます。
         | 
| 72 72 | 
             
            > 引用テキスト
         | 
| 73 | 
            -
            DevTools listening on ws://127.0.0.1: | 
| 73 | 
            +
            DevTools listening on ws://127.0.0.1:49835/devtools/browser/d77618c9-a3d6-4982-814e-034bac32c200
         | 
| 74 | 
            -
            [ | 
| 74 | 
            +
            [9312:13168:1219/164828.980:ERROR:device_event_log_impl.cc(211)] [16:48:28.980] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: システムに接続されたデバイスが機能していません。 (0x1F)
         | 
| 75 75 | 
             
            Traceback (most recent call last):
         | 
| 76 76 | 
             
              File "C:\Users\yagla\Program_lessons\Python\index.py", line 38, in <module>
         | 
| 77 77 | 
             
                titles, urls, count= search_page(driver)
         | 
| 78 78 | 
             
              File "C:\Users\yagla\Program_lessons\Python\index.py", line 24, in search_page
         | 
| 79 | 
            -
                title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md"))
         | 
| 79 | 
            +
                title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md").text)
         | 
| 80 80 | 
             
              File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 398, in find_element_by_class_name
         | 
| 81 81 | 
             
                return self.find_element(by=By.CLASS_NAME, value=name)
         | 
| 82 82 | 
             
              File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 658, in find_element
         | 
| @@ -88,5 +88,4 @@ | |
| 88 88 | 
             
              File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
         | 
| 89 89 | 
             
                raise exception_class(message, screen, stacktrace)
         | 
| 90 90 | 
             
            selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".LC20lb DKV0Md"}
         | 
| 91 | 
            -
             | 
| 92 91 | 
             
              (Session info: chrome=87.0.4280.88)
         | 
2
コンソールに書かれている情報を追加しました。
    
        title	
    CHANGED
    
    | 
            File without changes
         | 
    
        body	
    CHANGED
    
    | @@ -67,4 +67,26 @@ | |
| 67 67 |  | 
| 68 68 | 
             
            wb.save("scraping.xlsx")
         | 
| 69 69 |  | 
| 70 | 
            -
            ```
         | 
| 70 | 
            +
            ```
         | 
| 71 | 
            +
            実行すると以下のように出力されます。
         | 
| 72 | 
            +
            > 引用テキスト
         | 
| 73 | 
            +
            DevTools listening on ws://127.0.0.1:49192/devtools/browser/ed2754e1-b7b2-4f70-9563-6e9ebf346065
         | 
| 74 | 
            +
            [14264:7080:1219/163616.006:ERROR:device_event_log_impl.cc(211)] [16:36:16.005] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: システムに接続されたデバイスが機能していません。 (0x1F)
         | 
| 75 | 
            +
            Traceback (most recent call last):
         | 
| 76 | 
            +
              File "C:\Users\yagla\Program_lessons\Python\index.py", line 38, in <module>
         | 
| 77 | 
            +
                titles, urls, count= search_page(driver)
         | 
| 78 | 
            +
              File "C:\Users\yagla\Program_lessons\Python\index.py", line 24, in search_page
         | 
| 79 | 
            +
                title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md"))
         | 
| 80 | 
            +
              File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 398, in find_element_by_class_name
         | 
| 81 | 
            +
                return self.find_element(by=By.CLASS_NAME, value=name)
         | 
| 82 | 
            +
              File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 658, in find_element
         | 
| 83 | 
            +
                return self._execute(Command.FIND_CHILD_ELEMENT,
         | 
| 84 | 
            +
              File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
         | 
| 85 | 
            +
                return self._parent.execute(command, params)
         | 
| 86 | 
            +
              File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
         | 
| 87 | 
            +
                self.error_handler.check_response(response)
         | 
| 88 | 
            +
              File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
         | 
| 89 | 
            +
                raise exception_class(message, screen, stacktrace)
         | 
| 90 | 
            +
            selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".LC20lb DKV0Md"}
         | 
| 91 | 
            +
             | 
| 92 | 
            +
              (Session info: chrome=87.0.4280.88)
         | 
1
コードの修正
    
        title	
    CHANGED
    
    | 
            File without changes
         | 
    
        body	
    CHANGED
    
    | @@ -25,10 +25,10 @@ | |
| 25 25 |  | 
| 26 26 | 
             
                scraping_count = 0 #確認用変数
         | 
| 27 27 | 
             
                while page_number <= page_number_max:
         | 
| 28 | 
            -
                    class_group = driver. | 
| 28 | 
            +
                    class_group = driver.find_elements_by_class_name("rc") #クラス名だけ探す
         | 
| 29 29 | 
             
                    for class_name in class_group:
         | 
| 30 | 
            -
                        title_list.append(class_name. | 
| 30 | 
            +
                        title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md"))
         | 
| 31 | 
            -
                        url_list.append(class_name. | 
| 31 | 
            +
                        url_list.append(class_name.find_element_by_tag_name("a").get_attribute("href"))
         | 
| 32 32 | 
             
                        scraping_count += 1
         | 
| 33 33 |  | 
| 34 34 | 
             
                    if driver.find_elements_by_name("pnnext") == []: #次のページがなかったらループを抜け出す
         | 
