• 목록
  • 아래로
  • 위로
<script>
  var sub_show = "slide";
  var sub_hide = "";
  var menu_startAt = "5";
  var menu_sub = "";
  var menu_subAt = "50";
</script>

 

 

만약 위와 같은 자바스크립트에서 3번째 줄의 menu_startAt의 값(5)을 파싱한다면,

 

정규식을 사용하는 것이 일반적이겠지만

 

아래와 같이 split으로 해결하는 방법도 가능할 것입니다.

 

 

soup = BeautifulSoup(html, 'html5lib')
scripts = soup.findAll('script')
for s in scripts:
    if 'menu_startAt = "' in str(s):
        menu_startAt = str(sc).split('menu_startAt = "', 1)[-1].split('"', 1)[0]

 

 

물론 상황에 따라서는 json 모듈을 사용하는 방법을 적극적으로 고려해볼 수 있습니다.

 

아래 문서를 참조하세요 ^-^

 

https://stackoverflow.com/a/13298240

I am scraping some websites using BeautifulSoup and Requests. There is one page that I am examining t...

 

작성자
이니스프리 119 Lv. (1%) 2319890/115200000EXP

Make StudyForUs Great Again!

 

CSVpuymXAAAVVpd.jpg

댓글 0

권한이 없습니다.
번호 제목 글쓴이 날짜 조회 수
공지 [작업 완료] 설 명절 맞이 서버 업데이트 안내 3 마스터 마스터 24.02.11.17:21 1064
공지 [중요] 호스팅 만료와 관련하여 일부 수칙이 변경됩니다. 4 마스터 마스터 23.01.14.02:23 4755
34 [Python] MP4 움짤을 clip하여 thumbnail 生成하기 이니스프리 이니스프리 22.06.09.08:35 173
33 [Python] Bypassing Cloudflare's anti-bot page with Cloudscraper module 이니스프리 이니스프리 22.06.10.22:11 197
32 [Python] Function to save list into a text file line by line 이니스프리 이니스프리 22.06.11.21:33 166
31 [Selenium] Page down 이니스프리 이니스프리 22.06.19.12:40 168
30 [Filepond] 가로로 이미지 나열 이니스프리 이니스프리 22.06.20.21:26 259
29 [Telegram] Bot의 inline keyboard 제거 이니스프리 이니스프리 22.07.01.20:35 190
28 [Matplotlib] X축 눈금 레이블 텍스트를 회전시키는 방법 이니스프리 이니스프리 22.07.18.21:05 204
27 [Python] 문자열을 숫자 크기대로 정렬하기 이니스프리 이니스프리 22.07.21.19:57 590
26 [Python] Poppler 등 설치하지 않고 PDF -> Image 하는 모듈 이니스프리 이니스프리 22.07.28.11:20 227
25 [Python] PyMuPDF의 사용방법 이니스프리 이니스프리 22.07.28.21:33 499
24 [Python] Zip 파일에서 특정 확장자의 파일들만 특정 폴더에 압축 풀기 이니스프리 이니스프리 22.08.01.19:31 540
23 [Python] zipfile 모듈 한글 파일명 깨짐 현상 해결방법 이니스프리 이니스프리 22.08.03.19:37 852
22 [Vultr] 원클릭 NextCloud 설치 시 config.php 위치 이니스프리 이니스프리 23.03.05.10:16 245
21 [Python] Downloading Youtube Private Videos with Youtube_dlp - 유튜브 '비공개' 동영상 다운로드 이니스프리 이니스프리 23.06.30.20:05 310
20 [Python] How to send BOLD text with Telegram bot 이니스프리 이니스프리 23.08.10.19:51 216
19 [Python Requests] multiple cookies를 다루기 - "There are multiple cookies with name python" 에러 처리 이니스프리 이니스프리 23.08.22.01:40 281
18 [Python] CGV 예매 관련 크롤링 (개요) 이니스프리 이니스프리 23.08.22.21:10 426
17 [Python] Ordered Set 이니스프리 이니스프리 23.09.19.20:24 201
16 [디지털 포렌식 전문가] 제21회 실기 시험 일정 image 이니스프리 이니스프리 23.10.29.01:39 192
15 [Python] \u3000을 공백으로 치환하기 이니스프리 이니스프리 23.10.29.14:51 281