自己研鑽(python)

【selenium insta自動イイね】
from selenium import webdriver
from time import sleep
import random
import requests
from bs4 import BeautifulSoup

driver = webdriver.Chrome("#webdriverのパス入れる") 
driver.get("https://www.instagram.com/?hl=ja")
ctime = random.choice(range(3,15))
#ログイン
def login():
    # sleep(5)
    # elem_search_word = driver.find_element_by_xpath("//p[@class='izU2O']/a") 
    # elem_search_word.click()

    sleep(3)
    username = driver.find_element_by_name('username')
    username.send_keys('※ユーザー名入れる')

    password = driver.find_element_by_name('password')
    password.send_keys('※パスワード入れる')

    sleep(5)
    login = driver.find_element_by_xpath("//form[@class='HmktE']/div/button") 
    login.click()

    sleep(ctime)
    pop_up = driver.find_element_by_class_name('aOOlW')
    pop_up.click()

login()

#検索
def search():
    #検索したいタグを入れる
    randum = ['※タグ入れる']
    sleep(ctime)
    search_btn = driver.find_element_by_class_name('XTCLo')
    search_btn.send_keys(random.choice(randum))

    sleep(ctime)
    searth_btn_click = driver.find_element_by_css_selector('.fuqBx > a:first-child')
    searth_btn_click.click()

    sleep(ctime)
    searth_btn_click = driver.find_element_by_css_selector('.Nnq7C > div:first-child a')
    searth_btn_click.click()
    
    #イイねボタン
    #selectors
    LOGIN_PATH = '//*[@id="react-root"]/section/main/article/div[2]/div[2]/p/a'
    LIKE_PATH = '//button[@class="wpO6b "]/*[name()="svg"][@aria-label="いいね!"]'
    LIKE_BUTTON_PATH = '//button[@class="wpO6b "]'
    MEDIA_SELECTOR = 'div._9AhH0'
    NEXT_PAGE_SELECTOR = 'a.coreSpriteRightPaginationArrow'
    likedCounter = 0
    likedMax = 100

    while likedCounter < likedMax:
        sleep(3)
        try:
            driver.find_element_by_xpath(LIKE_PATH)
            driver.find_element_by_xpath(LIKE_BUTTON_PATH).click()
            likedCounter += 1
            print("{} イイね".format(likedCounter))
        except:
            print("pass")
            pass

        #次へ
        try:
            driver.find_element_by_css_selector(NEXT_PAGE_SELECTOR).click()
        except:
            break

    print("イイねが{}いったよー".format(likedCounter))
search()

制作期間:2日

【Line 天気予報】
import requests
from bs4 import BeautifulSoup
import schedule
# def job():
# 天気情報
z = 0
box1 = []
while True:
	z += 1
	r = requests.get('https://weather.yahoo.co.jp/weather/jp/11/?day=' + str(z) + '')
	soup = BeautifulSoup(r.content, "html.parser")
	days = soup.select_one('#navCal li:nth-of-type(' + str(z) + ')')
	days_wrap = days.getText()
	temp = soup.select_one('li.pt4310 .temp')
	temp_wrap = temp.getText()
	precip = soup.select_one('li.pt4310 .precip')
	precip_wrap = precip.getText()
	box1.append(days_wrap + ' ' + '最高/最低気温:' + temp_wrap.replace('\n', '') + '\n' + '降水確率:' + precip_wrap.replace('\n', ''))
	if z == 3:
		break
total = '\n' + box1[0] + '\n' + box1[1] + '\n' + box1[2]

# LINE
line_notify_token = '***********************************'
line_notify_api = 'https://notify-api.line.me/api/notify'
message = total

payload = {'message': message}
headers = {'Authorization': 'Bearer ' + line_notify_token}  # 発行したトークン
line_notify = requests.post(line_notify_api, data=payload, headers=headers)

制作期間:2日

Back to Top