Sto usando Python 2.7 con Selenium WebDriver. La mia domanda è come stampare l'intera pagina sorgente con il metodo print
. C'è del metodo WebDriver page_source
ma restituisce WebDriver e non so come convertirlo in stringa o semplicemente stamparlo nel terminalePython WebDriver come stampare l'intera pagina sorgente (html)
7
A
risposta
22
.page_source
su un'istanza webdriver
è quello che vi serve:
>>> from selenium import webdriver
>>> driver = webdriver.Firefox()
>>> driver.get('http://google.com')
>>> print(driver.page_source)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" itemtype="http://schema.org/WebPage" itemscope=""><head><meta name="descri
...
:before,.vscl.vslru div.vspib{top:-4px}</style></body></html>
0
È può anche ottenere l'origine della pagina HTML senza utilizzare un browser. Il modulo delle richieste ti consente di farlo.
import requests
res = requests.get('https://google.com')
res.raise_for_status() # this line trows an exception if an error on the
# connection to the page occurs.
print(res.text)
Problemi correlati
- 1. Come stampare il sorgente html su console con phantomjs
- 2. Come stampare le linee del codice sorgente nel logger python
- 3. Come ottengo il codice sorgente HTML dalla pagina?
- 4. Oggetto pagina Selenium WebDriver
- 5. React.js stampare testo come HTML
- 6. Come stampare il codice su HTML
- 7. pagina web Scorrimento usando il selenio python WebDriver
- 8. Ottieni codice sorgente HTML come stringa
- 9. watir-webdriver attendere caricamento pagina
- 10. Come ottenere la Sorgente della Pagina in Protractor
- 11. HTML WebDriver Problemi con Ajax
- 12. Python Web Crawler e codice sorgente "get" sorgente
- 13. come stampare l'intero elemento HTML in JavaScript?
- 14. Come leggere e stampare il testo con newline da una stringa Python (Django) con HTML?
- 15. Python: come estrarre l'URL dalla pagina HTML usando BeautifulSoup?
- 16. Come estrarre gli URL da una pagina HTML in Python
- 17. Come passaggio del mouse in python WebDriver
- 18. Come stampare forzatamente l'immagine di sfondo in HTML?
- 19. Come commentare l'attributo tag HTML nel codice sorgente HTML?
- 20. Selenium scarica la pagina full html
- 21. Java WebDriver attende il caricamento della pagina
- 22. Selenio WebDriver esempio in Python
- 23. Come generare un PDF da un sorgente HTML/CSS (incluso immagini) in Python?
- 24. Invia pagina HTML Come email utilizzando "mutt"
- 25. Come misurare a livello di codice le dimensioni degli elementi nel codice sorgente HTML usando python?
- 26. File tmp Python Firefox Webdriver
- 27. Python Selenium Webdriver - Autenticazione proxy
- 28. Come oscuro l'intera pagina? (html)
- 29. Python - Selenium WebDriver - Esiste l'elemento di controllo
- 30. Rileva audio con Selenium Webdriver e Python
Grazie, questo è esattamente ciò di cui ho bisogno! Questa è stata colpa mia perché ho fatto in modo errato 'print driver.page_source' (driver.page_source non era tra parentesi) – wmarchewka