2024-05-13 10:35:24 发布
网友
我可以使用urllib获得html页面,并使用BeautifulSoup解析html页面,看起来我必须生成要从BeautifulSoup读取的文件。
import urllib sock = urllib.urlopen("http://SOMEWHERE") htmlSource = sock.read() sock.close() --> write to file
有没有办法在不从urllib生成文件的情况下调用BeautifulSoup?
from BeautifulSoup import BeautifulSoup soup = BeautifulSoup(htmlSource)
无需编写文件:只需传入HTML字符串。还可以直接传递从urlopen返回的对象:
urlopen
f = urllib.urlopen("http://SOMEWHERE") soup = BeautifulSoup(f)
无需编写文件:只需传入HTML字符串。还可以直接传递从
urlopen
返回的对象:相关问题 更多 >
编程相关推荐