在爬取中,如果链接是有规则的增加+1。使用.format()非常方便
for i in range(1,10): num = i url = "https://cchheenn.com/index.php?chaps={}".format(num); # 需要请求的网址 print(url)
输出结果为
https://cchheenn.com/index.php?chaps=1 https://cchheenn.com/index.php?chaps=2 https://cchheenn.com/index.php?chaps=3 https://cchheenn.com/index.php?chaps=4 https://cchheenn.com/index.php?chaps=5 https://cchheenn.com/index.php?chaps=6 https://cchheenn.com/index.php?chaps=7 https://cchheenn.com/index.php?chaps=8 https://cchheenn.com/index.php?chaps=9