概述
-
import urllib.request
-
import urllib.parse
-
url='http://www.baidu.com'
-
hearder={
-
'User-Agent':'Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
-
}
-
request=urllib.request.Request(url,headers=header)
-
reponse=urllib.request.urlopen(request).read()
-
fhandle=open("./1.html","wb")
-
fhandle.write(reponse)
-
# -*- coding: utf-8 -*-
-
import urllib.request
-
import urllib.parse
-
url='http://www.baidu.com/s?wd='
-
key='fengxin的博客'
-
key_code=urllib.request.quote(key) #因为URL里含中文,需要进行编码
-
url_all=url+key_code
-
header={
-
'User-Agent':'Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
-
} #头部信息
-
request=urllib.request.Request(url_all,headers=header)
-
reponse=urllib.request.urlopen(request).read()
-
fh=open("./baidu.html","wb") #写入文件中
-
fh.write(reponse)
-
fh.close()
-
#!/usr/bin/env python3
-
# -*- coding: utf-8 -*-
-
import urllib.request
-
import urllib.parse
-
url='http://www.iqianyue.com/mypost'
-
header={
-
'User-Agent':'Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
-
}
-
data={'name':'fengxin','pass':'123'}
-
postdata=urllib.parse.urlencode(data).encode('utf8') #进行编码
-
request=urllib.request.Request(url,postdata)
-
reponse=urllib.request.urlopen(request).read()
-
fhandle=open("./1.html","wb")
-
fhandle.write(reponse)
最后
以上就是鳗鱼微笑为你收集整理的python pandas 用法大全之爬虫的全部内容,希望文章能够帮你解决python pandas 用法大全之爬虫所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复