import requests
import urllib.request
from bs4 import BeautifulSoup

print('loading...')

url = 'https://item.taobao.com/item.htm?spm=a21wu.241046-kr.4691948847.15.2549b6cbIrG2cS&scm=1007.15423.84311.100200300000001&id=563998572434&pvid=db1ba01b-cf08-4758-a822-b454552f7b1bid}'
r = requests.get(url, verify=False)
html = r.text
soup = BeautifulSoup(html, 'html.parser')
imgUrl = soup.select('#J_DivItemDesc>div.content')[0]['src']
urllib.request.urlretrieve(f'http:{imgUrl}''337.jpg')


코드 전문


PS C:\Users\ksjyh\Desktop\pythonproject> python prototype.py

loading...

C:\Users\ksjyh\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py:979: InsecureRequestWarning: Unverified HTTPS request is being made to host 'item.taobao.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

  warnings.warn(

Traceback (most recent call last):

  File "prototype.py", line 11, in

    imgUrl = soup.select('#J_DivItemDesc>div.content')[0]['src']

IndexError: list index out of range

PS C:\Users\ksjyh\Desktop\pythonproject>


오류 내용

링크의 상품소개 사진을 떼오려는 중인데

인덱스에 뭐가 없다고 하는 걸 보면 내가 설정을 잘못한 듯 함...

뭐가 문제인지 알겠는 사람 있으면 도움 좀 주라...