python中url代表什么_python – urlopen(‘http …’)中的read()是什么.read()吗? [的urllib]...

嗨,我正在阅读“使用

Python进行Web Scraping(2015)”.我看到了以下两种打开url的方法,使用和不使用.read().请参阅bs1和bs2

from urllib.request import urlopen

from bs4 import BeautifulSoup

html = urlopen('http://web.stanford.edu/~zlotnick/TextAsData/Web_Scraping_with_Beautiful_Soup.html')

bs1 = BeautifulSoup(html.read(), 'html.parser')

html = urlopen('http://web.stanford.edu/~zlotnick/TextAsData/Web_Scraping_with_Beautiful_Soup.html')

bs2 = BeautifulSoup(html, 'html.parser')

bs1 == bs2 # true

print(bs1.prettify()[0:100])

print(bs2.prettify()[0:100]) # prints same thing

那么.read()是多余的吗?谢谢

使用python进行Web scpraing的p7代码:(使用.read())

from urllib.request import urlopen

from bs4 import BeautifulSoup

html = urlopen("http://www.pythonscraping.com/pages/page1.html")

bsObj = BeautifulSoup(html.read())

第15页的代码(没有.read())

from urllib.request import urlopen

from bs4 import BeautifulSoup

html = urlopen("http://www.pythonscraping.com/pages/warandpeace.html")

bsObj = BeautifulSoup(html)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值