第一个Python爬虫

原文链接:https://blog.csdn.net/sunon_/article/details/90634253

mport urllib.request

import chardet

page = urllib.request.urlopen('http://www.meituba.com/tag/juesemeinv.html') #打开网页

htmlCode = page.read() #获取网页源代码

#print(chardet.detect(htmlCode)) #查看编码方式

data = htmlCode.decode('utf-8')

#print(data) #打印网页源代码

pageFile = open('pageCode.txt','wb')#以写的方式打开pageCode.txt

pageFile.write(htmlCode)#写入

pageFile.close()#开了记得关
————————————————

原文链接:https://blog.csdn.net/sunon_/article/details/90634253

猜你喜欢

转载自www.cnblogs.com/youngqianger/p/11961376.html