파이썬 크롤링으로 preview나 response값 가져오기
조회수 1754회
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 답변
-
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'},...
댓글 입력