2014-12-10 8 views

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> 
+2

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

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