Skip to content
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

파이썬 requestsbeautifulsoup 으로 웹 input에 입력값 대입한 뒤 결과값 파일로 저장하기

 

 


import requests
from bs4 import BeautifulSoup
 
url = "http://www.limc.co.kr/KpnInfo/KpnResultList_Rsult.asp?search_check=1"
 
# POST 요청을 위한 데이터 설정
payload = {
    'search_value': '1401',
}
 
# POST 요청 보내기
response = requests.post(url, data=payload)
 
# BeautifulSoup으로 HTML 파싱
soup = BeautifulSoup(response.text, 'html.parser')
 
#<----- 필요없는 부분 ----->
# 필요한 항목 추출
#title = soup.find('title').text
 
# description 추출 (None 체크)
#description_tag = soup.find('meta', {'name': 'description'})
#description = description_tag['content'] if description_tag else None
 
# 결과를 출력 또는 다른 작업 수행
#print("Title:", title)
#print("Description:", description)
#<----- 필요없는 부분 ----->





 
# 특정 부분의 th 태그들을 모두 찾기 (예시로 summary 속성이 '이 표는 혈통정보를 나타내는 테이블입니다.'인 표의 th 태그를 찾음)
th_elements = soup.find('div', class_='c6bg').find_all('th')
 
# th 태그들의 텍스트를 리스트에 저장
th_values = [th.text.strip() for th in th_elements]
 
# 특정 부분의 td 태그들을 모두 찾기 (예시로 클래스가 'c6bg'인 div 안의 td 태그를 찾음)
td_elements = soup.find('div', class_='c6bg').find_all('td')
 
# td 태그들의 텍스트를 리스트에 저장
td_values = [td.text.strip() for td in td_elements]
 
# 결과 출력
#print("TD Values:", td_values)
#print("TD Values:", td_values[1])
print(th_values[1], td_values[1])
 
# 특정 부분의 th 태그들을 모두 찾기 (예시로 summary 속성이 '이 표는 혈통정보를 나타내는 테이블입니다.'인 표의 th 태그를 찾음)
ta_elements = soup.find('table', class_='t04').find_all('th')
 
print()
# th 태그들의 텍스트를 리스트에 저장
ta_values = [ta.text.strip() for ta in ta_elements]
 
# 결과 출력
print("Table>th Values:", ta_values)
print("Table>th Values:", ta_values[1])
print(ta_values[1], ta_values[1])


 

#한글이 깨질때~~~~

# CP949로 디코딩하여 복원
restored_list = [s.encode('latin1').decode('cp949') for s in ta_values]
 
# 결과 출력
print("복원된 리스트:", restored_list)

 

# 결과값을 파일에 저장
with open("result.html", "w", encoding=response.encoding) as file:
    file.write(response.text)
로그인 후 댓글쓰기가 가능합니다.

?

List of Articles
번호 분류 제목 날짜 조회 수
60 AVR 아두이노 전압측정(오실레이터가 없을때 활용) file 2013.10.18 27385
59 AVR 555 TIMER AM TRANSMITTER CIRCUIT(AM 송신 회로) file 2014.09.20 23298
58 AVR ARDUINO 명령어 모음 3 2012.07.24 22842
57 AVR 열전도율 높은 금속 순위 1 2013.06.25 22833
56 AVR 정전압 레귤레이터 1 5 2012.08.11 20392
55 AVR LTC871 DC to DC 부스터 컨버터 스텝업 (LTC1871 DC-DC Boost converter Adjustable Step-Up High Power Supply Module Red LED Voltage meter) file 2014.08.14 19509
54 AVR 태양광 전지필름을 이용한 스마트폰 충전기 만들기 2 file 2012.10.31 19487
53 AVR 열전 소자[ thermoelement , 熱電素子 ] file 2013.06.25 16724
52 AVR 아두이노 업로드 통신 설정방법 file 2019.06.13 15745
51 AVR 아두이노(우노UNO)와 HC-06 블루투스 모듈 연결하기(성공) 2 5 file 2012.08.17 13875
50 AVR 아두이노 Uno + Thermistor 온도센서 사용해보기 3 file 2012.08.05 13758
49 AVR 회로도, 마이컴, 브레드보드 사용방법 등 3 2012.07.18 13370
48 AVR 아두이노로 할 수 있는 아이디어 및 프로젝트, 기타 정보 모음 2 1 2012.08.30 13159
47 AVR 아두이노 카페 2013.08.17 12556
46 AVR 가변저항 3 file 2012.07.18 12130
45 AVR Arduino 특정시간 제어와 릴레이 다루기 2019.06.13 11935
44 AVR 아두이노 Uno + Cds Cell 5파이 광(빛감지) 감지센서 사용해보기 1 1 file 2012.08.05 11908
43 AVR 5V로 정전압 출력하기 2013.06.28 11837
42 AVR 안드로이드 스마트폰 + 블루투스 통신 + 아두이노 자동차 2 2012.08.03 11560
41 AVR 아두이노 예제) LED 속도 가속 또는 랜덤화 하기 + 시리얼 통신까지 20 2012.08.04 11292
Board Pagination Prev 1 2 3 Next
/ 3

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소