Python小程式刷超星學習通課程的訪問量

2022-05-17 19:39:09 字數 1838 閱讀 1630

解決方法:

print("首次登入,請在瀏覽器手動登入!")

d.get(starturl)

webdriverwait(d, 1000).until(

ec.url_to_be(starturl)

)with open("cookies.json", "w", encoding="utf-8") as f:

json.dump(d.get_cookies(), f)

def main():

ft = float(input("請輸入重新整理頻率(0.1 - 10)建議直接輸入1:"))

#starturl = "" 輸入學習介面url,下面的鏈結是個例子,請自己更改

starturl = ""

#'f:\google chrome x64\chromedriver.exe'是驅動位址,請自己更改

d = webdriver.chrome(r'f:\google chrome x64\chromedriver.exe')

if os.path.exists("cookies.json"):

print("自動登入ing...")

d.get(starturl)

with open("cookies.json", "r", encoding="utf-8") as f:

for cookie in json.load(f):

if "expiry" in cookie:

del cookie['expiry']

d.add_cookie(cookie)

d.get(starturl)

if d.current_url == starturl:print("自動登入成功!")

else: login(d, starturl)

else: login(d, starturl)

while true:

cells = d.find_elements_by_class_name("cells")

if d.current_url!=starturl:

print("被攔截啦!請輸入驗證碼繼續操作")

webdriverwait(d, 1000).until(

ec.url_to_be(starturl)

)for cell in cells:

try:

cel = cell.find_elements_by_class_name("ncells")

for ce in cel:

time.sleep(ft)

print(ce.text)

ce.click()

except:

#請忽略此行d.get("")

d.get(starturl)

break

#可選擇手動關閉

#d.close()

if __name__ == "__main__":

main()

參考資料:

python實現小程式 python實現小程式

1 楊輝三角形python實現 1 11 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 楊輝三角形 def triangel n l 1 定義乙個list 1 while true yield l 列印出該list l l x l x 1 for x in range le...

python練習小程式

1.今年是否為閏年 import time thisyear time.localtime 0 print time.localtime if thisyear 400 0 or thisyear 4 0 and thisyear 100!0 print this year s is leap ye...

python實現小程式

1 楊輝三角形python實現 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 楊輝三角形 def triangel n l 1 定義乙個list 1 while true yield l 列印出該list l l x l x 1 for x in range...