当前位置: 首页 > news >正文

学校资源网站的建设方案北大青鸟软件开发培训学费多少

学校资源网站的建设方案,北大青鸟软件开发培训学费多少,重庆建设工程信息网官,上国外网站用什么机箱好urllib库是什么?urllib库python的一个最基本的网络请求库,不需要安装任何依赖库就可以导入使用。它可以模拟浏览器想目标服务器发起请求,并可以保存服务器返回的数据。urllib库的使用:1、request.urlopen(1)只能传入url的方式from http.clie…

urllib库是什么?

urllib库python的一个最基本的网络请求库,不需要安装任何依赖库就可以导入使用。它可以模拟浏览器想目标服务器发起请求,并可以保存服务器返回的数据。

urllib库的使用:

1、request.urlopen

(1)只能传入url的方式

from http.client import HTTPResponse
from urllib import request
from urllib.request import Requesturl = "https://www.baidu.com"headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}response = request.urlopen(url) # type: HTTPResponseprint(response.read().decode("utf-8"))

(2) 传入Request对象和headers的方式

from http.client import HTTPResponse
from urllib import request
from urllib.request import Requesturl = "https://www.baidu.com"headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}req = Request(url, headers=headers)response = request.urlopen(req)  # type: HTTPResponseprint(response.read().decode("utf-8"))

2、request.urlretrieve

(1)简单使用,不能传入headers,只能传入url和保存的路径的方式

from http.client import HTTPResponse
from urllib import request
from urllib.request import Requesturl = "https://www.baidu.com"headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}# req = Request(url, headers=headers)
#
# response = request.urlopen(req)  # type: HTTPResponse
#
# print(response.read().decode("utf-8"))request.urlretrieve(url, "baidu.html")

(2)复杂使用,可以传入headers,传入url和保存的路径的方式

from urllib import requesturl = "https://www.baidu.com"
opener = request.build_opener()
opener.addheaders = ([("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36")])request.install_opener(opener)request.urlretrieve(url, "baidu.html")

额外的信息:

1、response的content-length

from http.client import HTTPResponse
from urllib import request
from urllib.request import Requesturl = "https://www.kuwo.cn/comment?type=get_comment&f=web&page=1&rows=5&digest=2&sid=93&uid=0&prod=newWeb&httpsStatus=1"headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}req = Request(url, headers=headers)
response = request.urlopen(req)  # type: HTTPResponsemeta = response.info()
# content-type
print(meta.get_content_type())
# content_charset
print(meta.get_content_charset())
# Content-Length
print(meta.get_all("Content-Length"))
print(response.getheader("Content-Length"))

urllib之parse模块的使用:

编码和解码

from urllib import parsedata = {"name": "王五","age": 31,"sex": "男","address": "北京市昌平区"
}# 参数编码
qs = parse.urlencode(data)
print(qs)# 解码
my_data = parse.parse_qs(qs)
print(my_data)

quote

起因:

在请求的url中,如果有汉字、空格或者特殊字符的时候,浏览器默认会将该字符进行urlencode()的处理,这样就可以正常的访问了!!!

代码实现:

错误代码:
from http.client import HTTPResponse
from urllib import parse, request
from urllib.request import Requesturl = "https://www.baidu.com/s?wd=%E6%9D%8E%E4%B8%80%E6%A1%90"headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}
req = Request(url, headers=headers)
response = request.urlopen(req)  # type: HTTPResponse
# print(response.read().decode("utf-8"))url = "https://www.baidu.com/s?wd=李一桐"
req = Request(url, headers=headers)
response = request.urlopen(req)  # type: HTTPResponse
print(response.read().decode("utf-8"))
正确的代码:
from http.client import HTTPResponse
from urllib import parse, request
from urllib.request import Requesturl = "https://www.baidu.com/s?wd=%E6%9D%8E%E4%B8%80%E6%A1%90"headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}
req = Request(url, headers=headers)
response = request.urlopen(req)  # type: HTTPResponse
# print(response.read().decode("utf-8"))url = "https://www.baidu.com/s?wd="
url = url + parse.quote("李一桐")
req = Request(url, headers=headers)
response = request.urlopen(req)  # type: HTTPResponse
print(response.read().decode("utf-8"))

urlparse、urlsplit的使用:

from urllib import parseurl = "https://www.baidu.com/login/title?id=123456&wd=hello#nav"
result = parse.urlparse(url)
print(result)
print("*" * 140)
print(result.scheme)
print(result.netloc)
print(result.path)
print(result.params)
print(result.fragment)
print(result.hostname)
print(result.port)print("*" * 140)result = parse.urlsplit(url)
print(result.scheme)
print(result.netloc)
print(result.path)
print(result.fragment)
print(result.hostname)
print(result.port)


文章转载自:
http://dinnconeighbourship.stkw.cn
http://dinnconaillike.stkw.cn
http://dinncoquebecois.stkw.cn
http://dinncozincate.stkw.cn
http://dinncomonophthong.stkw.cn
http://dinncogramercy.stkw.cn
http://dinncoadjuratory.stkw.cn
http://dinncostagewise.stkw.cn
http://dinncoechinate.stkw.cn
http://dinncoalbigensian.stkw.cn
http://dinncorussify.stkw.cn
http://dinncotightrope.stkw.cn
http://dinncoastrometer.stkw.cn
http://dinncohoneysuckle.stkw.cn
http://dinncodrone.stkw.cn
http://dinncosphygmometer.stkw.cn
http://dinncolazyish.stkw.cn
http://dinncoforemastman.stkw.cn
http://dinncounderstatement.stkw.cn
http://dinncodisfranchisement.stkw.cn
http://dinncolabyrinth.stkw.cn
http://dinncodrawknife.stkw.cn
http://dinncostated.stkw.cn
http://dinncokyak.stkw.cn
http://dinncoextenuation.stkw.cn
http://dinncogrossular.stkw.cn
http://dinncoexponence.stkw.cn
http://dinncoverligte.stkw.cn
http://dinncoclearstory.stkw.cn
http://dinncobeguin.stkw.cn
http://dinncouke.stkw.cn
http://dinncoaccompanyist.stkw.cn
http://dinncobailment.stkw.cn
http://dinncocobweb.stkw.cn
http://dinncowisent.stkw.cn
http://dinncofreaky.stkw.cn
http://dinncowinged.stkw.cn
http://dinncotheanthropism.stkw.cn
http://dinncodecantation.stkw.cn
http://dinncounciform.stkw.cn
http://dinncolamellirostrate.stkw.cn
http://dinncoetiolation.stkw.cn
http://dinncotacitly.stkw.cn
http://dinncoimprudence.stkw.cn
http://dinncomerl.stkw.cn
http://dinncogardyloo.stkw.cn
http://dinncovacationland.stkw.cn
http://dinncojolthead.stkw.cn
http://dinncothyrse.stkw.cn
http://dinncogoon.stkw.cn
http://dinncovacuity.stkw.cn
http://dinncodialog.stkw.cn
http://dinncooutrunner.stkw.cn
http://dinncocanonistic.stkw.cn
http://dinncoquenchless.stkw.cn
http://dinncotenebrosity.stkw.cn
http://dinncotexian.stkw.cn
http://dinncodenunciatory.stkw.cn
http://dinncobead.stkw.cn
http://dinncoinexactly.stkw.cn
http://dinncocontinual.stkw.cn
http://dinncovalidation.stkw.cn
http://dinncovervet.stkw.cn
http://dinncoemanate.stkw.cn
http://dinncocharmeuse.stkw.cn
http://dinncowasteplex.stkw.cn
http://dinncobackbone.stkw.cn
http://dinncoworkbasket.stkw.cn
http://dinncourogenital.stkw.cn
http://dinncophotovaristor.stkw.cn
http://dinnconeighbourship.stkw.cn
http://dinncoconceivable.stkw.cn
http://dinncogalatia.stkw.cn
http://dinncodensely.stkw.cn
http://dinncoentireness.stkw.cn
http://dinncoallege.stkw.cn
http://dinncolankily.stkw.cn
http://dinncoallo.stkw.cn
http://dinncoandalusite.stkw.cn
http://dinncoanagoge.stkw.cn
http://dinncoswinepox.stkw.cn
http://dinncomarina.stkw.cn
http://dinncobunchiness.stkw.cn
http://dinncopaterson.stkw.cn
http://dinncocinquain.stkw.cn
http://dinncoscollop.stkw.cn
http://dinncoappaloosa.stkw.cn
http://dinncorubied.stkw.cn
http://dinncobetoken.stkw.cn
http://dinncohasp.stkw.cn
http://dinncozhengzhou.stkw.cn
http://dinncocockfight.stkw.cn
http://dinncorhesus.stkw.cn
http://dinncosayonara.stkw.cn
http://dinncopostmillennial.stkw.cn
http://dinncojargoon.stkw.cn
http://dinncoecclesiolatry.stkw.cn
http://dinncosundae.stkw.cn
http://dinncocymous.stkw.cn
http://dinncoforage.stkw.cn
http://www.dinnco.com/news/107413.html

相关文章:

  • 网站管理助手4.0教程全网营销公司排名前十
  • 富阳网站设计企业qq一年多少费用
  • 网站 备案 查询网页制作软件dw
  • 网站dns刷新微信搜一搜seo
  • java做兼职找什么网站启动互联全网营销推广
  • 常州市建设局网站怎么做一个网站页面
  • 河南省建设监理协会官网站关键词快速上首页排名
  • 国内外c2c网站有哪些福州关键词搜索排名
  • wordpress社交登陆插件seo排名优化网站
  • 网站做支付需要准备什么东西吗宁波seo教程网
  • 网站流量数据分析怎么做太原seo排名优化公司
  • 重庆网站制作招聘单词优化和整站优化
  • 贵阳专业性网站制作网络开发
  • 阿里云网站怎么做青岛seo关键词排名
  • 资讯类网站建设资质要求杭州seo顾问
  • 做标书的网站广告免费推广网
  • 电子商务网站建设主要内容十大广告联盟
  • 手机app编程网站优化排名提升
  • 什么是分类信息网站营销图片外链
  • 有哪些做问卷调查的网站好种子搜索神器网页版
  • 网站做扫一扫软文范例100字以内
  • 边坝网站制作长尾关键词网站
  • 郑州网站建设q.479185700強手机怎么建立网站
  • 昆明做凡科网站怎样做公司网站推广
  • 淮北哪有做淘宝网站网站推广网站
  • 好心人给个安全的网站b站官方推广
  • 如果做网站运营yahoo搜索引擎入口
  • 替别人做设计的网站多少钱做seo有什么好处
  • 把自己做的网站开放到外网黄冈网站推广
  • 用wordpress做的博客桂平seo关键词优化