Mar-25-2018, 07:24 PM
Thank you for an excellent tutorial.
I had to make two changes to make the Selenium (How Secure is Your Password?) example at the bottom of the tutorial to run. Please let me know what I was doing wrong, as I expected the code to run 'as is'.
The items I changed were:
a. Moved the browser.close() line to the bottom of the file.
b. Changed (last line) 'print(bottom.text)' to 'print(bottom_text.text)'
The following is 'cut and paste' of the original code with comments next to changes I had to make.
See https://python-forum.io/Thread-Web-scraping-part-2
Lewis
I had to make two changes to make the Selenium (How Secure is Your Password?) example at the bottom of the tutorial to run. Please let me know what I was doing wrong, as I expected the code to run 'as is'.
The items I changed were:
a. Moved the browser.close() line to the bottom of the file.
b. Changed (last line) 'print(bottom.text)' to 'print(bottom_text.text)'
The following is 'cut and paste' of the original code with comments next to changes I had to make.
See https://python-forum.io/Thread-Web-scraping-part-2
from selenium import webdriver from selenium.webdriver.common.keys import Keys from bs4 import BeautifulSoup import time #browser = webdriver.PhantomJS() browser = webdriver.Firefox() url = 'https://howsecureismypassword.net/' browser.get(url) inputElement = browser.find_elements_by_class_name("password-input")[0] inputElement.send_keys("123hello") inputElement.send_keys(Keys.RETURN) time.sleep(3) browser.close() #Should probably be moved either to the end of the file or to after the last use of 'browser' whichever is more 'Pythonic' # Give source code to BeautifulSoup soup = BeautifulSoup(browser.page_source, 'html.parser') # Crack time info top_text = soup.select_one('.result__text.result__before') crack_time = soup.select_one('.result__text.result__time') bottom_text = soup.select_one('.result__text.result__after') print(top_text.text) print(crack_time.text) print(bottom.text) #Should probably be print(bottom_text.text)Thank you.
Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00