0
url = 'http://www.xxx'
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')

s1 = soup.find_all(id="contents")
print(s1, "\n")

The output of the find_all:

[<div id="contents" style="width:1000px;padding:10px 0;overflow:hidden;"><table style="margin:0;width:1000px;overflow:hidden;" width="980">
<tr><td style="text-align:center;">
<img src="http://xxx/shop/data/editor/2020090302-01.jpg"/></td></tr></table>
</div>] 

How can I get the src of the img tag from the results?
Do I have any way to get the url instead of the id="contents" option?
What I just want is the URL from the result.

maciejwww
  • 1,067
  • 1
  • 13
  • 26
SOO KIM
  • 15
  • 5
  • Can you add the exact url which you are scrapping? – ParthS007 Sep 19 '20 at 08:23
  • http://www.cobaro.co.kr/shop/goods/goods_view.php?goodsno=8719&category=003004 here we go! From the url above. What I want is to get the url of the image! which is [] – SOO KIM Sep 19 '20 at 08:27
  • Remember, to break a text line you can use two spaces on the end of the line. Opening a new paragraph (one line break between text lines) is not recommended with no reason - it takes too much space on the page. – maciejwww Sep 19 '20 at 11:40

1 Answers1

1

You can get the src of the img in the div like this:

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'])
Output:

http://cobaro.co.kr/shop/data/editor/2020090302-01.jpg
ParthS007
  • 2,581
  • 1
  • 22
  • 37
  • Sure! I will upvoting! btw this is my first Question so... I will try in 2 weeks right? cause I found that I'm not possible to vote but have to wait for 2 wekks? – SOO KIM Sep 19 '20 at 09:22
  • @SOOKIM If my answer helped you, consider upvoting and accepting so that other users will find it useful too. – ParthS007 Oct 07 '20 at 20:29