1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

オードリーの出演・イベントをseleniumで取得する

1
Posted at

技術

  • python3
  • selenium
  • slackweb
  • AWS Lambda(別で記事書きたい)

コード

明日の出演・イベント取得
import time
import slackweb
from selenium import webdriver
from datetime import datetime, timedelta, timezone

JST = timezone(timedelta(hours=+9), 'JST')
tomorrow = (datetime.now(JST)+timedelta(days=1)).strftime("%Y/%m/%d")

options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)

driver.get('http://www.kdashstage.jp/profile/archives/39')
time.sleep(3)
element = driver.find_element_by_class_name("Appearances")
h2 = element.find_element_by_tag_name("h2")

message = ""
list = element.find_element_by_class_name("psize")
for i in range(len(driver.find_elements_by_xpath('//*[@id="Profile"]/section[2]/div/dl'))):
    dl = driver.find_elements_by_xpath('//*[@id="Profile"]/section[2]/div/dl')[i]
    day = dl.find_element_by_class_name('day').text

    if day == tomorrow:
        time = dl.find_element_by_class_name('time').text
        contents = dl.find_element_by_tag_name('dd').text
        message += day + " " + time + " " + contents + "\n"

slack = slackweb.Slack(url="slackのwebhookURL")
attachments = []
attachment = {
    "title": "明日のオードリー出演・イベント予定",
    "pretext": "トゥース:point_up:",
    "text": message,
    "mrkdwn_in": ["text", "pretext"],
    "color": "#ffddff"
    }
attachments.append(attachment)
slack.notify(attachments=attachments, username="リトルトゥース", icon_emoji=":point_up")

driver.quit()

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?