Python-csdnブログのトップページを登る
2364 ワード
# csdn
import urllib.request
import re
url="https://blog.csdn.net/"
#
headers=("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36 SE 2.X MetaSr 1.0")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
#
urllib.request.install_opener(opener)
data=urllib.request.urlopen(url).read().decode("utf-8","ignore")
pat='A=re.compile(pat).findall(data)
for i in range(0,len(A)):
localpath="E:\\daima\\"+str(i)+".html"
B=A[i]
urllib.request.urlretrieve(B,filename=localpath)
print(「 の 」+str(i)+「 り 」)