Python BeautifulSoup从find_all的结果中查找url url='1〕http://www.xxx' html=urllib.request.urlopen(url.read()) soup=BeautifulSoup(html,'html.parser') s1=汤。查找所有(id=“内容”) 打印(s1,“\n”)
Python BeautifulSoup从find_all的结果中查找url url='1〕http://www.xxx' html=urllib.request.urlopen(url.read()) soup=BeautifulSoup(html,'html.parser') s1=汤。查找所有(id=“内容”) 打印(s1,“\n”),python,python-3.x,beautifulsoup,bs4dash,Python,Python 3.x,Beautifulsoup,Bs4dash,find_all的输出: [ ] 如何从结果中获取img标记的src 我是否有办法获取url而不是id=“contents”选项? 我只需要结果的URL。您可以在div中获得img的src,如下所示: from bs4 import BeautifulSoup as bs import urllib url = 'http://www.cobaro.co.kr/shop/goods/goods_view.php?goodsno=8719&category=003004' html
find_all
的输出:
[
]
如何从结果中获取img
标记的src
我是否有办法获取url而不是id=“contents”
选项?我只需要结果的URL。您可以在div中获得img的
src
,如下所示:
from bs4 import BeautifulSoup as bs
import urllib
url = 'http://www.cobaro.co.kr/shop/goods/goods_view.php?goodsno=8719&category=003004'
html = urllib.request.urlopen(url).read()
soup = bs(html, 'html.parser')
divs = soup.find_all(id="contents")
for div in divs:
img_tag = div.find('img')
print(img_tag['src'])
你能添加你正在废弃的确切url吗?我们走!从上面的url。我想要的是得到图像的url!这是[]“rel=”nofollow noreferrer“>cobaro.co.kr/shop/data/editor/2020090302-01.jpg”/>记住,要打断文本行,可以在行的末尾使用两个空格。不建议无缘无故地打开一个新段落(文本行之间有一个换行符),因为这会占用页面太多空间。当然!我会投票的!顺便说一句,这是我的第一个问题,所以。。。我会在两周内试一试,对吗?因为我发现我不可能投票,但是必须等待2个Wekk?”SooKIM如果我的回答帮助了你,考虑一下投票和接受,这样其他用户也会发现它有用。
Output:
http://cobaro.co.kr/shop/data/editor/2020090302-01.jpg