use*_*419 8 python image urllib
有人可以帮我解析一个html文件来获取python中文件中所有图像的链接吗?
最好不要使用第三方模块......
谢谢!
Rus*_*ias 10
你可以使用美丽的汤.我知道你说没有第三方模块.但是,这是解析HTML的理想工具.
import urllib2
from BeautifulSoup import BeautifulSoup
page = BeautifulSoup(urllib2.urlopen("http://www.url.com"))
page.findAll('img')
Run Code Online (Sandbox Code Playgroud)
Kab*_*bie 10
只使用PSL
from html.parser import HTMLParser
class MyParse(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag=="img":
print(dict(attrs)["src"])
h=MyParse()
page=open("index.html").read()
h.feed(page)
Run Code Online (Sandbox Code Playgroud)