版权声明:未经同意窃取和转载我的内容,如果涉及到权益问题,后果自负! https://blog.csdn.net/weixin_41605937/article/details/84261595
urllib.request.urlretrieve("http://www.youku.com/",filename="./网页/数据挖掘实例网页.html")
#这是网页下载到本地文件中
urllib.request.urlcleanup()
#清理缓存
file=urllib.request.urlopen("http://www.hellobi.com")
print("环境信息:",file.info())
# getcode()状态编码
# geturl()获取网页的函数
print(file.getcode())
print(file.geturl())
#解决网址中含有中文的乱码问题
keywd=urllib.request.quote(“中文”)
#模拟http请求 通过post和get 两种方式来请求,比如登入和搜索的信息的时候可能会用到。
#爬虫的网址
html = "http://www.iqianyue.com/mypost/"
#设置表单数据
mydata=urllib.parse.urlencode({ "name":"[email protected]", "pass":"5695262623" }).encode("utf-8")
#设置请求
req=urllib.request.Request(html,mydata)
#提交的网址,提交的信息
data=urllib.request.urlopen(req).read()
#写入文件 fw=open("./作业二","wb")
fw.write(data)
fw.close()