亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python程序查看用戶選擇的同一網頁的次數

Python程序查看用戶選擇的同一網頁的次數

函數式編程 2021-08-05 18:06:59
我試圖打開相同的所需網頁(由用戶)選定的次數,但我似乎無法讓它工作。#Imports modulesimport requestsimport time#Assigning variables to stringsimport urllib.requesturl = "https://r6tab.com/bd6a3f35-5060-499a-8645-369664aae1d9"# Open the URL as Browser, not as python urllibhow = input("Enter how many views you want!")for counter in range (0,how):     page=urllib.request.Request(url,headers={'User-Agent': 'Mozilla/5.0'})     infile=urllib.request.urlopen(page).read()Traceback (most recent call last):  File "C:/Users/lauchlan/Desktop/sss.py", line 14, in <module>    for counter in range (0,how):TypeError: 'str' object cannot be interpreted as an integer>>> 修復了錯誤,但網頁上的瀏覽量沒有計算在內
查看完整描述

2 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

input返回一個字符串。您需要轉換為整數才能在range. 嘗試:
how = int(input("Enter how many views you want!"))

查看完整回答
反對 回復 2021-08-05
  • 2 回答
  • 0 關注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號