Beispiel #1
0
            print(
                '링크',
                li.find_element_by_css_selector('a').get_attribute('onclick'))
            print('상품명', li.find_element_by_css_selector('h5.proTit').text)
            print('코멘트', li.find_element_by_css_selector('.proSub').text)
            print('가격', li.find_element_by_css_selector('.proPrice').text)
            area = ''
            for info in li.find_elements_by_css_selector('.info-row .proInfo'):
                print(info.text)
            print('=' * 100)
            # 데이터 모음
            # li.find_elements_by_css_selector('.info-row .proInfo')[1].text
            # 데이터가 부족하거나 없을수도 있으므로 직접 인덱스로 표현은 위험성이 있음
            obj = TourInfo(
                li.find_element_by_css_selector('h5.proTit').text,
                li.find_element_by_css_selector('.proPrice').text,
                li.find_elements_by_css_selector('.info-row .proInfo')[1].text,
                li.find_element_by_css_selector('a').get_attribute('onclick'),
                li.find_element_by_css_selector('img').get_attribute('src'))
            tour_list.append(obj)
    except Exception as e1:
        print('오류', e1)

print(tour_list, len(tour_list))

# 수집한 정보 개수를 루프 => 페이지 방문 => 콘텐츠 획득(상품상세정보) => 디비
for tour in tour_list:
    print(type(tour))
    arr = tour.link.split(',')
    if arr:
        # 대체
        link = arr[0].replace('searchModule.OnClickDetail(', '')
                  li.find_element_by_css_selector('img').get_attribute('src'))
            print(
                '링크 : ',
                li.find_element_by_css_selector('a').get_attribute('onclick'))
            print('상품명 : ', li.find_element_by_css_selector('h5.proTit').text)
            print('코멘트 : ', li.find_element_by_css_selector('p.proSub').text)
            print('가격 : ',
                  li.find_element_by_css_selector('strong.proPrice').text)
            for info in li.find_elements_by_css_selector('.info-row .proInfo'):
                print(info.text)
            print('=' * 100)
            # 데이터 모음
            obj = TourInfo(
                li.find_element_by_css_selector('h5.proTit').text,
                li.find_element_by_css_selector('strong.proPrice').text,
                # 데이터가 부족하거나 없을 수도 있으므로 직접 인덱스로 표현하면 위험성이 있음
                li.find_elements_by_css_selector('.info-row .proInfo')[1].text,
                li.find_element_by_css_selector('a').get_attribute('onclick'),
                li.find_element_by_css_selector('img').get_attribute('src'))
            tour_list.append(obj)
    except Exception as e1:
        print('오류', e1)

print(tour_list, len(tour_list))

#수집한 정보 개수를 루프 돌려서 페이지 방문 => 컨텐츠 획득 (상품 상세정보) => DB
for tour in tour_list:
    # tour => TourInfo
    print(type(tour))
    # 링크데이터에서 실데이터 획득
    # 분해
Beispiel #3
0
            # 이미지는 링크값을 사용할 것인가? 직접 다운로드해서 서버(ftp)에 업로드 할 것인가?
            # print("썸네일 :", li.find_element_by_css_selector("img").get_attribute("src"))
            # print("링크 :", li.find_element_by_css_selector("a").get_attribute("onclick"))
            # print("상품명 :", li.find_element_by_css_selector("h5.proTit").text)
            # print("코멘트 :", li.find_element_by_css_selector("p.proSub").text)
            # print("가격 :",   li.find_element_by_css_selector("strong.proPrice").text)
            # for info in li.find_elements_by_css_selector(".info-row .proInfo"):
            #     print(info.text)
            # print("=================================="*2)
            # 데이터 모음
            # li.find_elements_by_css_selector(".info-row .proInfo")[1].text
            # 데이터가 부족하거나 없을 수도 있으므로 직접 인덱스로 표현하는 것은 위험성이 있음
            obj = TourInfo(
                li.find_element_by_css_selector("h5.proTit").text,
                li.find_element_by_css_selector("strong.proPrice").text,
                li.find_elements_by_css_selector(".info-row .proInfo")[1].text,
                li.find_element_by_css_selector("a").get_attribute("onclick"),
                li.find_element_by_css_selector("img").get_attribute("src")
            )
            tour_list.append(obj)
    except Exception as e1:
        print( '오류', e1)

print("총 개수 :", len(tour_list))

# 수집한 정보 개수를 루프 => 페이지 방문 -> 컨텐츠 획득(상품상세정보) -> DB
for tour in tour_list:
    #tour -> TourInfo
    # print( type(tour) )
    # 링크 데이터에서 실데이터 획득
    #분해
Beispiel #4
0
    #proTit, proSub, proPrice, proInfo, img, onClick의 주소, proInfo, boxItem
    #<li class="boxItem">
    time.sleep(2)
    boxItems = driver.find_elements_by_css_selector(
        '.oTravelBox > .boxList > .boxItem')

    for box in boxItems:
        price = box.find_element_by_css_selector('strong.proPrice').text
        price = re.sub(r',', '', price.split(' ')[0])
        price = int(price)
        point = box.find_elements_by_css_selector('p.proInfo')[2].text
        period1 = box.find_elements_by_css_selector('p.proInfo')[0].text
        period2 = box.find_elements_by_css_selector('p.proInfo')[1].text
        obj = TourInfo(
            box.find_element_by_css_selector('h5.proTit').text, price,
            box.find_element_by_css_selector('p.proSub').text,
            float(point.split(' ')[1]),
            period1.split(':')[1].strip(),
            period2.split(":")[1].strip())
        mylist.append(obj)

driver.close()

import pymongo
from pymongo import MongoClient

client = MongoClient('localhost', 27017)
db = client.test
info = db['TourInfo']
try:
    for mytour in mylist:
        db.info.insert({