“”"
Created on Tue Aug 4 10:47:12 2020
@author: Judy
“”"
import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = input('Enter URL: ')
count = int(input('Enter count: '))
position = int(input('Enter position: '))
while count > 0:
html = urllib.request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, ‘html.parser’)
tags = soup(‘a’)
url = tags[position-1].get(‘href’,None)
print(url)
count = count -1
玄学,跑了一天总是卡循环,发给朋友看了看,然后就能跑出来了