파이썬 크롤링으로 preview나 response값 가져오기

조회수 1756회

http://vod.afreecatv.com/TVCLIP 해당 페이지에서 크롬 개발자 도구 네트워크에서

get_smr_list.php 라는걸 볼수있는데요 이것을 클릭하고 preview나 response에 가보면 이미지

여러 값들이 나와서 이것들을 가져오려고 아래코드를 실행시켜 봤는데요

import requests
from bs4 import BeautifulSoup as bs
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'
    }
crawlUrl = 'http://stbbs.afreecatv.com/api/get_smr_list.php'
crawl = requests.get(crawlUrl,headers=header)
print(crawl.text)

실행결과 아래처럼 get_smr_list.php 를 더블클릭 했을때 나오는 값을 줍니다

{"result":-3,"error":"\uc8c4\uc1a1\ud569\ub2c8\ub2e4. \uc7a0\uc2dc \ud6c4 \ub2e4\uc2dc \uc2dc\ub3c4\ud574 \uc8fc\uc2dc\uace0 \ubb38\uc81c\uac00 \ud574\uacb0\ub418\uc9c0 \uc54a\uc740 \uacbd\uc6b0 \uace0\uac1d\uc13c\ud130\ub85c \ubb38\uc758\ud574 \uc8fc\uc138\uc694."}

사진에 있는 값들을 가져오려면 어떻게 해야하는지 도움을 구합니다

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    get 이 아니라 post 로 호출해야 합니다.

    import requests
    from bs4 import BeautifulSoup as bs
    
    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'
        }
    crawlUrl = 'http://stbbs.afreecatv.com/api/get_smr_list.php'
    crawl = requests.post(crawlUrl, data={'command':'mainList+', 'device':'PC'}, headers=header)
    print(crawl.json())
    {'result': 1, 'data': {'cpList': [{'cpid': 'CC', 'corporatorcode': 'tvchosun', 'corporatorname': 'TV조선'}, {'cpid': 'CF', 'corporatorcode': 'mbn', 'corporatorname': 'MBN'}, {'cpid': 'CD', 'corporatorcode': 'channela', 'corporatorname': '채널A'}, {'cpid': 'CE', 'corporatorcode': 'jtbc', 'corporatorname': 'JTBC'}, {'cpid': 'CG', 'corporatorcode': 'cjenm', 'corporatorname': 'CJ ENM'}, {'cpid': 'C3', 'corporatorcode': 'kbs', 'corporatorname': 'KBS'}, {'cpid': 'C2', 'corporatorcode': 'mbc', 'corporatorname': 'MBC'}, {'cpid': 'C1', 'corporatorcode': 'sbs', 'corporatorname': 'SBS'},...
    
    • 와 정말감사합니다 그런데 data={'command':'mainList+', 'device':'PC'} 이부분을 넣어야된다는걸 어떻게 아신건가요? get_smr_list.php 랑 form data를 하나하나 다봐도 저런게 안보여서요 nyw123 2020.2.8 02:32
    • headers 탭에 보면 하단에 form data 라고 나타납니다. 정영훈 2020.2.8 03:45
    • 바로앞에두고 못찾았다니 제눈이 잠시 맛이 갔었네요 ㅎㅎ; nyw123 2020.2.9 02:35

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)