Python Forum
Questions abou Web-scraping part-2 Tutorial
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Questions abou Web-scraping part-2 Tutorial
#1
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
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply
#2
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.
Reply
#3
snippsat,

Thank you for your response.

Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Two part scraping? never5000 1 1,275 Feb-23-2022, 03:49 PM
Last Post: snippsat
  Detect comments part using web scraping seco 7 4,866 Jan-18-2018, 10:06 PM
Last Post: seco

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020