Python程序查看用户选择的同一网页的次数

我试图打开相同的所需网页(由用户)选定的次数,但我似乎无法让它工作。


#Imports modules

import requests

import time


#Assigning variables to strings

import urllib.request


url = "https://r6tab.com/bd6a3f35-5060-499a-8645-369664aae1d9"


# Open the URL as Browser, not as python urllib

how = 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

>>> 

修复了错误,但网页上的浏览量没有计算在内


函数式编程
浏览 169回答 2
2回答

哈士奇WWW

input返回一个字符串。您需要转换为整数才能在range.&nbsp;尝试:how = int(input("Enter how many views you want!"))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python