선숙 블로그에서 셀레니움으로 낚시 정보를 얻어봤어요.

6266 단어 PythonSeleniumtech

코드


import chromedriver_binary
import re
from datetime import datetime

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://shinmyomaru.com/category/tyouka')
browser.find_elements_by_class_name('readmore')[0].click()
results = []
for i in range(10):
    element_title = browser.find_element_by_class_name('entry-title')
    element_content = browser.find_element_by_class_name('entry-content')
    results.append(element_content.text)
    browser.find_element_by_class_name('previous').click()

for result in results:
    if 'マゴチ船' in result:
        searched_magochi = re.search(r'\d*〜\d*(?=本)', result)
        searched_date = re.search(r'\d\d?月\d\d?日', result)

        date_result = datetime.strptime('2020年' + searched_date[0], '%Y年%m月%d日').date()
        min_result_magochi, max_result_magochi = searched_magochi.group(0).split('〜')[:2]

        print(date_result)
        print('min: ' + min_result_magochi)
        print('max: ' + max_result_magochi)

결실


2020-09-16
min: 0
max: 8
2020-09-15
min: 0
max: 12
2020-09-14
min: 1
max: 5
2020-09-13
min: 0
max: 7
2020-09-12
min: 1
max: 5
2020-09-11
min: 0
max: 4
2020-09-09
min: 0
max: 5
2020-09-08
min: 0
max: 2
2020-09-06
min: 0
max: 4
2020-09-05
min: 0
max: 7

주의


selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 86
Current browser version is 85.0.4183.121 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
위의 오류가 발생하면 버전을 정렬합니다.
pip3 install chromedriver-binary==85.0.4183.87
제가 85세대 버전을 지정해서 설치한 후에 작동을 시작했습니다.

좋은 웹페이지 즐겨찾기