µð½Ã °¶·¯¸®¿¡¼ À̹ÌÁö¸¦ ±Ü¾î¿À´Â Å©·Ñ¸µÀ» ¸¸µé·Á´Âµ¥
½ÇÇàÇÏ¸é ¿À·ù°¡ ³ª³×¿ä
import urllib
from urllib import request
import requests
from bs4 import BeautifulSoup
from socket import timeout
site='http://gall.dcinside.com/board/view/?id=iu_new&no='
fileNo = 0
try:
for no in range(1778524, 1778548):
url=site+str(no)
source_code=requests.get(url)
plain_text=source_code.text
soup=BeautifulSoup(plain_text,'lxml')
iu=soup.find_all('li',{'class':"icon_pic"})
print(iu)
for url in iu:
href=url.get('href')
contents=urllib.request.urlopen(href)
content=contents.read()
open(str(fileNo)+'.jpg','wb').write(content)
fileNo=fileNo+1
except timeout:
print('shit')
else:
print('success')
<½ÇÇà½Ã ¿À·ù>
Traceback (most recent call last):
File "C:/Users/beench/Desktop/co/racing.py", line 19, in
contents=urllib.request.urlopen(href)
File "C:\Anaconda3\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Anaconda3\lib\urllib\request.py", line 456, in open
req.timeout = timeout
AttributeError: 'NoneType' object has no attribute 'timeout'
ã¾Æº¸´Ï±ñ urllib.request.urlopen(href) ºÎºÐÀÌ ¹®Á¦ÀΰŠ°°Àºµ¥ ÇØ°áÃ¥À» ¸ð¸£°Ú³×¿ä | |
|