2017-04-06 14 views
1

htmlパス全体を印刷する方法があるのだろうかと思っていました。私は、PDFのxhtmlファイルのポップアップでいくつかのテキストを検証しようとしており、に到達することができません。私の望みは、ページ全体のソースを取得し、テキストがそこにあることを確認することです。しかし.page_sourceは私にURLと説明だけを与えるようですが、私はコードの各行を取得しようとしています。Python Selenium XHTMLのページソースを取得する

+0

あなたは提案されたソリューションをテストしましたか? – aberna

答えて

0

可能なアプローチは、セレンが開始ページタグ(html)を見つけて、すべてのソース関連のコードを取得することです。

driver = webdriver.Firefox() 
driver.get("http://stackoverflow.com/") 
driver.find_element_by_tag_name("html").get_attribute('outerHTML') 

Documentation

出力例:

<html webdriver="true"><head> 

<title>Stack Overflow</title> 
    <link rel="shortcut icon" href="https://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d"> 
    <link rel="apple-touch-icon image_src" href="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a"> 
    <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml"> 
    <meta name="twitter:card" content="summary"> 
    <meta name="twitter:domain" content="stackoverflow.com"> 
    <meta property="og:type" content="website"> 
    <meta name="description" content="Stack Overflow is the largest online community for programmers to learn, share their knowledge, and advance their careers"> 

    <meta property="og:image" itemprop="image primaryImageOfPage" content="https://cdn.sstatic.net/Sites/stackoverflow/img/[email protected]?v=73d79a89bded"> 
    <meta name="twitter:title" property="og:title" itemprop="title name" content="Stack Overflow"> 
    <meta name="twitter:description" property="og:description" itemprop="description" content="Q&amp;A for professional and enthusiast programmers"> 
    <meta property="og:url" content="http://stackoverflow.com/"> 

...... 
関連する問題