標籤:__name__ rand view not range name keyword username coding
1 # coding=utf-8 2 from selenium import webdriver 3 from time import sleep 4 import keyword 5 from selenium.webdriver.common.keys import Keys 6 from selenium.webdriver.support.wait import WebDriverWait 7 from selenium.webdriver.support.ui import Select 8 import csv 9 import random10 import io11 12 # 滾動捲軸`13 def MoveScorllBar(driver, down, range1, range2):14 moneCount = random.randint(range1, range2)15 for num in range(1, moneCount):16 if (down == "down"):17 driver.find_element_by_xpath("//body").send_keys(Keys.DOWN)18 sleep(random.uniform(0.1, 0.5))19 else:20 driver.find_element_by_xpath("//body").send_keys(Keys.UP)21 sleep(random.uniform(0.1, 0.5))22 return23 24 if __name__ == "__main__":25 26 27 # 開啟瀏覽器,進入網站28 driver = webdriver.Chrome()29 driver.get("https://www.incnjp.com/home.php?mod=space&do=notice&view=system")30 # MoveScorllBar(driver, "down", 10, 30)31 #MoveScorllBar(driver, "up", 10, 30)32 33 username = ‘豬豬寶丫‘34 password = ‘guoqi0511‘35 36 # 輸入想要搜尋的商品-->點擊搜尋按鈕37 driver.find_element_by_xpath("//*[@id=‘lsform‘]/div/div/table/tbody/tr/td[3]/a").click()38 driver.find_element_by_id("logicon1").click()39 #driver.find_element_by_name("username").send_keys(username)40 #driver.find_element_by_name("password").send_keys(password)41 driver.find_element_by_name("loginsubmit").click()42 #driver.find_element_by_xpath("// *[ @ id = ‘J-search‘] / div[1] / a / span").click()
【Python】小春網爬爬