vps上でseleniumをつかってスクレイピングを行いたいのですが、コードはもともと使ってたpythonコード(同社のvpsでは実行可能)を用いてやってみると最初の一回だけは実行すると要素を取得することができましたが2回目以降は要素は取得できないのにエラーはでません。
python3
1import discord,asyncio,codecs 2from selenium.common.exceptions import NoSuchElementException 3from selenium.webdriver.chrome.options import Options 4from selenium import webdriver 5from selenium.webdriver.common.by import By 6from selenium.webdriver.support.ui import WebDriverWait 7from selenium.webdriver.support import expected_conditions as EC 8import chromedriver_binary 9client = discord.Client() 10async def snkrs(url): 11 ch = client.get_channel(チャンネルID) 12 b = 0 13 rtn1 = False 14 exist = False 15 while True: 16 options = Options() 17 options.add_argument('--headless') 18 options.add_argument('--no-sandbox') 19 options.add_argument('--disable-gpu') 20 options.add_argument('--window-size=1280,1024') 21#AIR FEAR OF GOD 22 wd = webdriver.Chrome(options=options) 23 wd.implicitly_wait(10) 24 wd.get(url) 25 try: 26 rtn1 = 'カートに追加'in wd.find_element_by_css_selector('.buying-tools-container').text 27 except NoSuchElementException: 28 rtn1 = False 29 exist1 = True 30 if rtn1 == True and b == 0: 31 str1 = '商品名' 32 str2 = wd.find_element_by_css_selector('.ncss-brand.text-color-grey.u-uppercase.mb-1-sm.mb0-md.fs14-sm.fs16-m 33d').text + ' ' 34 str3 = wd.find_element_by_css_selector('.rr-title.ncss-brand.u-uppercase.fs20-sm.fs32-lg.pb2-sm').text 35 str4 = '価格' 36 str5 = wd.find_element_by_css_selector('.ncss-brand.pb6-sm.fs14-sm.fs16-md').text 37 str6 = 'URL' 38 str7 = "[SNKRS]("+url+")" 39 element = wd.find_elements_by_class_name('image-component')[1] 40 str8 = element.get_attribute("src") 41 sizes = wd.find_elements_by_css_selector(省略) 42 i = 0 43 await ch.send(str1+str2+...省略) 44 b = 1 45 elif rtn1 == True and b == 1 or exist == True: 46 b = b 47 else: 48 b = "" 49 #b = 0 50 wd.close() 51 wd.quit() 52@client.event 53async def on_ready(): 54 loop = asyncio.get_event_loop() 55 t1 = asyncio.ensure_future(snkrs("https://www.nike.com/jp/launch/t/air-fear-of-god-raid-light-bone/")) 56 t3 = asyncio.ensure_future(snkrs("https://www.nike.com/jp/launch/t/air-fear-of-god-moc-black-fossil/")) 57 t4 = asyncio.ensure_future(snkrs("https://www.nike.com/jp/launch/t/air-vapormax-plus-on-air-paris/")) 58 t5 = asyncio.ensure_future(snkrs("https://www.nike.com/jp/launch/t/acg-react-terra-gobe-deep-jungle/")) 59 t6 = asyncio.ensure_future(snkrs("https://www.nike.com/jp/launch/t/air-fear-of-god-moc-black-fossil/")) 60 t7 = asyncio.ensure_future(snkrs("https://www.nike.com/jp/launch/t/air-fear-of-god-moc-pure-platinum/")) 61 t8 = asyncio.ensure_future(snkrs("https://www.nike.com/jp/launch/t/air-fear-of-god-moc-particle-beige/")) 62 tasks = asyncio.wait([t1,t3,t4,t5,t6,t7,t8]) 63client.run(TOKEN)
試したこと
1.VPSの再起動
2.実行中のプロセス終了
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。