Last active
January 17, 2019 12:26
-
-
Save umihico/eb738c7335bc5a254c2bea3831aa0011 to your computer and use it in GitHub Desktop.
ヤフーオークション再出品スクリプト selenium & python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from selenium.webdriver import Chrome, ChromeOptions | |
Chrome.xpath = Chrome.find_element_by_xpath | |
Chrome.xpaths = Chrome.find_elements_by_xpath | |
from time import sleep | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions | |
def logined(self): | |
return bool(self.xpaths("//div[@class='yjmthloginarea']/a[text()='ログアウト']")) | |
Chrome.logined = logined | |
def republish(): | |
userdata_dir = 'UserData' | |
os.makedirs(userdata_dir, exist_ok=True) | |
chromeoptions = ChromeOptions() | |
chromeoptions.add_argument('--user-data-dir=' + userdata_dir) | |
chrome = Chrome(chrome_options=chromeoptions) | |
url = "https://auctions.yahoo.co.jp/closeduser/jp/show/mystatus?select=closed&hasWinner=0" | |
chrome.get(url) | |
while True: | |
if chrome.logined(): | |
break | |
sleep(1) | |
while True: | |
chrome.refresh() | |
resell_buttons = chrome.find_elements_by_xpath( | |
"//a[./img[@alt='再出品']]") | |
if not resell_buttons: | |
break | |
resell_buttons[0].click() | |
try: | |
chrome.find_element_by_xpath("//td[@class='decFormTab01Off']/p/a").click() | |
except Exception as e: | |
pass | |
wait = WebDriverWait(chrome, 20) | |
wait.until(expected_conditions.visibility_of_element_located( | |
(By.XPATH, "//input[@value='確認画面へ' or @value='確認する']"))).click() | |
chrome.find_element_by_xpath( | |
"//input[@id='auc_preview_submit_up' or @value='ガイドラインに同意して出品する']").click() | |
chrome.get(url) | |
if __name__ == '__main__': | |
republish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment