Commit fbdf950a authored by Bradon Ladd's avatar Bradon Ladd
Browse files

Merge branch 'laddbr/lab9' into 'master'

Laddbr/lab9

See merge request !9
parents 1852b850 23046446
Pipeline #21107 passed with stages
in 2 minutes and 47 seconds
......@@ -2,4 +2,5 @@ area/area.exe
area/test.exe
.vscode/
msg.txt
lab07/build.bat
\ No newline at end of file
lab07/build.bat
dump.txt
\ No newline at end of file
1) Selenium sure was slower than using requests, but still a heck of a lot faster than doing it manually, still. The biggest difference that stood out to me was how little code
we actually needed to get something similar done using requests. Rather than interact with the UI itself with Selenium, we could bypass all that and have requests interact with the
page directly. This cut down on extra code, and we didn't need a class definition either. Really fascinating stuff.
I only ran into one issue, and that was using Requests. I wasn't entirely sure how to use requests natively to grab javascript generated HTML, so at the time of writing, I've
left it as is. But I imagine if I wanted to get it done, I'd have to use something like Beautiful Soup and maybe continue to use Selenium for my GET requests. I saw a few resources online
claim that using something called urllib2 could also grab javascript generated content. This seems to be Requests' only drawback.
\ No newline at end of file
Rem this is just a file that lets me hit "CTRL-SHIFT-B" in VSCode to build an executable
@echo off
@echo "Building Lab 7"
g++ -o lab-07/lab7 lab-07/main.cpp
import sys
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class ASWWU:
def __init__(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(5) # seconds
self.driver.get('https://aswwu.com/')
def searchMask(self, name):
xpath = "//a[contains(@href, 'https://aswwu.com/mask')]"
self.driver.find_element_by_xpath(xpath).click()
self.driver.find_element_by_id('mask-search-query').send_keys(name, Keys.ENTER)
self.driver.implicitly_wait(5) # seconds
xpath = "//search-results[contains(@ng-reflect-query,'" + name + "')]"
self.driver.find_element_by_xpath(xpath)
xpath = "//h4[contains(text(),'" + name + "')]"
result = self.driver.find_elements_by_xpath(xpath)
return result
# Logout code. I wasn't sure
def close(self):
self.driver.find_element_by_id('bubbleicon').click()
self.driver.find_element_by_xpath("//div[@class='dropdown-menu show']/button").click()
# add login() [x], updateProfile(), and close() to ASWWU
# iterate over a dictionary with `for key, value in dict.items():`
def main():
names = [ "Benko", "DePaula", "Fairchild", "Hartman", "Herbel",
"Hernandez", "Jones", "Moody", "Price", "Reklai", "Riggs",
"Smith", "Sukachevin", "Taylor", "Thomsen", "Tinker" ]
start = time.time()
aswwu = ASWWU()
for name in names:
aswwu.searchMask(name)
aswwu.close()
end = time.time()
print(end - start)
if __name__ == "__main__":
main()
import sys
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
def main():
names = [ "Benko", "DePaula", "Fairchild", "Hartman", "Herbel",
"Hernandez", "Jones", "Moody", "Price", "Reklai", "Riggs",
"Smith", "Sukachevin", "Taylor", "Thomsen", "Tinker" ]
start = time.time()
for name in names:
r = requests.get("https://aswwu.com/mask/search?query=" + name)
print(r.text, r.status_code)
end = time.time()
print(end - start)
# def main():
# names = [ "Benko", "DePaula", "Fairchild", "Hartman", "Herbel",
# "Hernandez", "Jones", "Moody", "Price", "Reklai", "Riggs",
# "Smith", "Sukachevin", "Taylor", "Thomsen", "Tinker" ]
# start = time.time()
# aswwu = ASWWU()
# for name in names:
# aswwu.searchMask(name)
# aswwu.close()
# end = time.time()
# print(end - start)
if __name__ == "__main__":
main()
1644416924833 geckodriver INFO Listening on 127.0.0.1:1110
1644416927874 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "--marionette" "--remote-debugging-port" "1111" "-no-remote" "-profile" "C:\\Users\\brado\\AppData\\Local\\Temp\\rust_mozprofilegVWrlr"
1644416928213 Marionette INFO Marionette enabled
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at C:\\Users\\brado\\AppData\\Local\\Temp\\rust_mozprofilegVWrlr\\search.json.mozlz4", (void 0)))
DevTools listening on ws://localhost:1111/devtools/browser/d33cff45-7ea3-40a9-8402-bd73912835c5
1644416930291 Marionette INFO Listening on port 1117
1644416930576 RemoteAgent WARN TLS certificate errors will be ignored for this session
1644417206861 Marionette INFO Stopped listening on port 1117
console.warn: TopSitesFeed: Failed to fetch data from Contile server: NetworkError when attempting to fetch resource.
###!!! [Parent][PGPUParent] Error: RunMessage(msgname=PGPU::Msg_ShutdownVR) Channel closing: too late to send/recv, messages will be lost
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment