2011-08-15 5 views
5

자바 스크립트를 많이 사용하는 HTML 문서를 어떻게 파싱하나요? 정적 XML/html 파일을 구문 분석 할 수있는 파이썬에서 몇 가지 라이브러리를 알고 기본적으로 html + 자바 스크립트를 읽는 프로그램이나 라이브러리 (또는 심지어 파이어 폭스 플러그인)를 찾고, javascript 비트를 실행하고 javascript없이 html 코드를 출력합니다. 브라우저에 표시되면 동일하게 보입니다. 간단한 예자바 스크립트 코드를 포함하는 HTML을 구문 분석하는 방법

<a href="javascript:web_link(34, true);">link</a> 

로서

자바 스크립트 함수 복귀, 예를 들어 적절한 값으로 대체되어야

<a href="http://www.example.com">link</a> 

더 복잡한 예는 많은 자바 스크립트 코드로 흩어져있는 저장된 페이스 북 HTML 페이지입니다.

아마도 How to "execute" HTML+Javascript page with Node.js 과 관련이 있습니다.하지만 실제로 Node.js와 JSDOM이 필요합니까? 또한 약간 관련이 Python library for rendering HTML and javascript 하지만 난 순수한 HTML 출력 렌더링에 관심이 아니에요. Mozilla Gecko FAQ에서

+0

어느 자바 스크립트 런타임을 얻고 그것으로 뭔가를 정렬 또는 코드를 분석하여 최종 결과 (강력한 사이트 별 구성)를 찾아 낼 수 있습니다. –

+0

http://stackoverflow.com/questions/19465510/how-to-parse-a-webpage-that-includes-javascript?rq=1 – gliptak

답변

2

: 당신이 유닉스 쉘 스크립트에서 게코 엔진을 호출 할 수 있습니다

Q.? HTML로 보내고 프린터로 전송 될 수있는 웹 페이지를 다시 가져올 수 있습니까?

A. 실제로 지원되지 않습니다. Gecko의 임베딩 API를 사용하여 자신 만의 응용 프로그램을 작성하여 원하는 것을 얻을 수 있습니다. 현재 렌더링 할 화면에 위젯이 없으면 인쇄 할 수 없습니다.

Embedding Gecko 당신이 원하는 것을 출력하는 프로그램은 너무 무거울 수 있지만 적어도 출력은 좋은 것입니다.

+0

이 제조법을 추가 할 수도 있습니다. http://siliconforks.com/doc/parsing -javascript-with-spidermonkey / –

3

당신은 자세한 here

예로서 파이썬으로 Selenium를 사용할 수 있습니다

import xmlrpclib 

# Make an object to represent the XML-RPC server. 
server_url = "http://localhost:8080/selenium-driver/RPC2" 
app = xmlrpclib.ServerProxy(server_url) 

# Bump timeout a little higher than the default 5 seconds 
app.setTimeout(15) 

import os 
os.system('start run_firefox.bat') 

print app.open('http://localhost:8080/AUT/000000A/http/www.amazon.com/') 
print app.verifyTitle('Amazon.com: Welcome') 
print app.verifySelected('url', 'All Products') 
print app.select('url', 'Books') 
print app.verifySelected('url', 'Books') 
print app.verifyValue('field-keywords', '') 
print app.type('field-keywords', 'Python Cookbook') 
print app.clickAndWait('Go') 
print app.verifyTitle('Amazon.com: Books Search Results: Python Cookbook') 
print app.verifyTextPresent('Python Cookbook', '') 
print app.verifyTextPresent('Alex Martellibot, David Ascher', '') 
print app.testComplete() 
0

PhantomJS를 사용하여로드 할 수 Selenium

$ ipython 

In [1]: from selenium import webdriver 

In [2]: browser=webdriver.PhantomJS() 

In [3]: browser.get('http://seleniumhq.org/') 

In [4]: browser.title 
Out[4]: u'Selenium - Web Browser Automation' 
관련 문제