Python Forum

Full Version: Questions abou Web-scraping part-2 Tutorial
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
Yes you right about changes Thumbs Up
Gone go trough part-2 as i have done with part-1 and update so all work.
There has been some changes,and now do both Chrome-driver and FireFox-driver(geckodriver),
support headless mode.
So PhantomJS is not needed anymore.
snippsat,

Thank you for your response.

Lewis