목록urllib (5)
아미(아름다운미소)
Python3 urllib으로 http로 POST 전송 ''' Created on 2019. 12. 21. @author: test ''' import urllib.parse import urllib.request details = urllib.parse.urlencode({'CODE': '코드', 'NAME': '이름', 'KIND': '종류', 'PRICE': '가격', 'USERID': '아이디'}) details = details.encode('UTF-8') url = urllib.request.Request('https://test.cafe24.com/postdata_test.php', details) url.add_header("User-Agent","Mozilla/5.0 (Windows; U..
HTTP GET in Python Python 3: import urllib.request contents = urllib.request.urlopen("http://test.com/?name=test&tel=01022223333").read() Python 2: import urllib2 contents = urllib2.urlopen("http://test.com/?name=test&tel=01022223333").read()
파이썬에서 파일을 다운로드하는 방법- Python 2에서 파일을 다운로드하는 방법 import urllib urllib.urlretrieve ("http://www.example.com/songs/mp3.mp3", "mp3.mp3") (Python 3+에서는 'import urllib.request'와 urllib.request.urlretrieve를 사용하십시오) - 파이썬에서 파일을로드하는 방법(진행 표시 줄) import urllib2 url = "http://download.thinkbroadband.com/10MB.zip" file_name = url.split('/')[-1] u = urllib2.urlopen(url) f = open(file_name, 'wb') meta = u.info()..
- 소스 코드(3.0기준)#_*_ coding:utf8 _*_ import urllib.request from bs4 import BeautifulSoup fp = urllib.request.urlopen('http://info.finance.naver.com/marketindex/exchangeList.nhn') source = fp.read() fp.close() class_list = ["tit","sale"] soup = BeautifulSoup(source,'html.parser') soup = soup.find_all("td", class_ = class_list) money_data={} for data in soup: if soup.index(data)%2==0: data=data.get_..
urllib/urllib2를 사용하고 있고 404에러와 기타 HTTP 에러를 점검하고 싶다면? 다음은 그 트릭이다: try: urlfile = urllib2.urlopen('http://sebsauvage.net/nonexistingpage.html') except urllib2.HTTPError, exc: if exc.code == 404: print "Not found !" else: print "HTTP request failed with error %d (%s)" % (exc.code, exc.msg) except urllib2.URLError, exc: print "Failed because:", exc.reason 이런 식으로 404에러와 기타 HTTP 에러 코드를 점검할 수 있다. urlli..