ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 배송조회 API 1(파이썬 코드)
    배송조회를 위한 크롤링소스 2023. 3. 9. 15:08
    from tracker import db 
    import requests
    from bs4 import BeautifulSoup
    import time
    
            
        url = "https://www.hanjin.com/kor/CMS/DeliveryMgr/WaybillSch.do?mCode=MN038"
        postUrl = "https://www.hanjin.com/kor/CMS/DeliveryMgr/WaybillResult.do"
        driver.get(url)
        time.sleep(3)
        soup = BeautifulSoup(driver.page_source, 'html.parser')
        
        rsaModule = soup.select_one("#RSAModulus").get('value')
        rsaExp = soup.select_one("#RSAExponent").get('value')
        pageResult = requests.post(postUrl,data={"mCode":"MN038","schLang":"KR","wblnumText":"","wblnum":invcNumber})
        respSoup = BeautifulSoup(pageResult.content, 'html.parser')
        transBody = respSoup.select_one('.waybill-tbl > .board-list-table > tbody')
        trandTrList = transBody.select('tr')
        
        complete = 'no'
        contents = []
        for tr in trandTrList:
            transList = tr.select('td')
            k=0
            item = {}
            date = '';
            for td in transList:
                k = k+1;
                text = td.get_text()
                if k==4:
                    findText = text.replace(' ','')
                  
                    if findText.find('배달완료') != -1:
                        complete = 'yes'
                    elif findText.find('배송완료') != -1:
                        complete = 'yes'
                        
                    item['step'] = text;
                    item['status'] = text;
                elif k==1:
                    date = text;
                elif k==2:
                    item['date'] = date+' '+text;
                elif k==3:
                    item['position'] = text;
                   
            contents.append(item)

    배송조회를 위해서는 먼저 파이썬으로 해당 택배사에서 정보를 크롤링 해야된다

    크롤링으로 사용할 언어로는 파이썬을 사용했다

     

     

Designed by Tistory.