MGMT 288 Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

what two things does the ? character signify in regular expressions?

"match zero or one of the preceding group" or be used to signify non-greedy matching

what is the CSS selector string that would find the element with an id attribute of main?

'#main'

what is the CSS selector string that would find the elements with a CSS class of highlight?

'.highlight'

what does the following expression evaluate to? 'Hello'.upper()

'HELLO'

What does the following expression evaluate to? 'Hello, world!'[0:5]

'Hello'

What does the following expression evaluate to? 'Hello, world!'[:5]

'Hello'

what does the following expression evaluate to? '-'join('There can be only one.'.split())

'There-can-only-be-one.'

what is the CSS selector string that would find the <button> element with a value attribute set to favorite?

'button[value="favorite"]'

what is the CSS selector string that would find all the <div> elements inside another <div> element?

'div div'

What does the following expression evaluate to? 'Hello, world!' [1]

'e'

what does the following expression evaluate to? 'Hello'.upper().lower()

'hello'

What does the following expression evaluate to? 'Hello, world!'[3:]

'lo, world!'

what are the three 'mode' arguments that can be passed to the open() function?

'r' for read, 'w' for write, 'a' for append

What is the difference between the + and * characters in regular expressions?

+ matches one or more. * matches zero or more

what are the . and .. folders?

. is the current folder, and .. is the parent folder

what does the . character normally match?

. normally matches any character except the newline character

what is the difference between .* and .*?

.* performs a greedy match, .*? performs a non-greedy match

In C:\bacon\eggs\spam.txt, which part is the dir name, and which part is the base name?

C:\bacon\eggs is the dir name. spam.txt is the base name

what are the five logging levels?

DEBUG, INFO, WARNING, ERROR, CRITICAL

what is the keyboard shortcut for opening a browser's developer tools?

F12 brings up the developer tools in Chrome

in the regex created from r'(\d\d\d)-(\d\d\d-\d\d\d\d', what does group 0 cover? group 1? group 2?

Group 0 is the entire match, group 1 covers the first set of parentheses, group 2 covers the second set of parentheses

how can you view the HTML of a specific element on a web page?

Right-click the element in the page and select Inspect Element from the menu

what happens if an existing file is opened in write mode?

The file will be erased and overwritten

what does the following expression evaluate to? 'Hello'.upper().isupper()

True

what does the following expression evaluate to? 'Remember, remember, the fifth of November.'.split()

['Remember,', 'remember,', 'the', 'fifth', 'of', 'November.']

how can you put a \ backslash character in a string?

\\ will put in a \ character

how do you save a requests response to a file?

after opening the new file in 'wb' mode, use a for loop that iterates over the Response object's iter_content() method to write out chunks to the file

Write an assert statement that always triggers an AssertionError

assert False, 'This assertion always triggers'

Write an assert statement that triggers an AssertionError if the variables eggs and bacon contain strings that are the same as each other, even if their cases are different

assert eggs.lower() != bacon.lower() 'The eggs and bacon variables are the same!' (can switch lower to upper)

Write an assert statement that triggers an AssertionError if the variable spam is an integer less than 10

assert spam >= 10, 'The spam variable is less than 10'

Parentheses and periods have specific meanings in regular expression syntax. How would you specify that you want a regex to match actual parentheses and period characters?

can be escaped using backslash \

what is the selenium module?

can launch and control a browser

what is step out?

causes the debugger to execute lines of code at full speed until it returns from the current function

what is step in?

causes the debugger to execute the next line of code and then pause again

What are escape characters?

characters in string values that would otherwise be difficult or impossible to type into code

how do you set a breakpoint on a line of code in Mu?

click the line number to make a red dot appear next to it

what methods do Selenium WebElement objects have for simulating mouse clicks and keyboard keys?

click() and send_keys()

what is the requests module?

downloads files and pages from the web

what is the character class syntax to match all numbers and lowercase letters?

either [0-9a-z] or [a-0-9]

what is step over?

executes the next line of code. if the next line is a function call, it will step over the code in the function

what's the difference between the find_element_* and find_elements_* methods?

find_element_* returns the first matching element as a WebElement object. find_elements_* returns a list of all matching elements in a WebElement object

How can you simulate clicking a browser's Forward, Back, and Refresh buttons with Selenium?

forward(), back(), and refresh() WebDriver object methods

How do you get the actual strings that match the pattern from a Match objects?

group() returns strings of the matched text

what is the webbrowser module?

has an open() method that will launch a web browser to a specific URL

The findall() method returns a list of strings or a list of tuples of strings. What makes it return one or the other?

if the regex has no groups, a list of strings is returned. If the regex has groups, a list of tuples of strings is returned

What are the two lines that your program must have in order to be able to call logging.debug()?

import logging logging.basicConfig(level=logging.DEBUG, format='%asctime)s - %(levelname)s - %(message)s')

running import selenium doesn't work. How do you properly import the selenium module?

imported with from selenium import webdriver

What does Path('C:/Users') / 'Al' evaluate to on Windows?

it evaluates to WindowsPath('C:/Users/Al'), will be same path on other operating systems but with different kind of Path object

What does the | character signify in regular expressions?

it signifies matching "either, or" between two groups

how would you store all the attributes of a Beautiful Soup Tag object in a variable named linkElem?

linkElem.attrs

what line of code can you add to disable all logging messages in your program?

logging.disable(logging.CRITICAL)

How can you trim whitespace characters from the beginning or end of a string?

lstrip() and rstrip()

If you don't want to put \n in your string, how can you write a string with newlines in it?

multiline strings, can use triple quotes

what does the \n escape character represent?

newline

What do the os.getcwd() and os.chdir() functions do?

os.getcwd() returns the current working directory. os.chdir() changes the current working directory

what is the bs4 module?

parses HTML

how do you make a regular expression case-insensitive?

passing re.I or re.IGNORECASE as the second argument to re.compile()

What requests method checks that the download worked?

raise_for_status() raises an exception if the download had problems and does nothing if the download succeeded

Why are raw strings often used when creating Regex objects?

raw strings are used so that backslashes do not have to be escaped

what is the function that creates Regex objects?

re.compile function returns Regex objects

How would you write a regex that matches a sentence where the first word is either Alice, Bob, or Carol; the second word is either eats, pets, or throws; the third word is apples, cats, or baseballs; and the sentence ends with a period? Should be case-insensitive.

re.compile(r'(Alice|Bob|Carol)\s(eats|pets|throws)\s(apples|cats|baseballs)\.',re.IGNORECASE)

how would you write a regex that matches the full name of someone whose last name is Watanabe? You can assume the first name will begin with a capital letter.

re.compile(r'[A-Z][a-z]*\sWatanabe')

How would you write a regex that matches a number with commas for every three digits?

re.compile(r'^\d{1,3}(,\d{3})*$')

what is the difference between the read() and readlines() methods?

read() returns the file's entire contents as a single string value. readlines() returns a list of strings, where each string is a line from the contents

What is a relative path relative to?

relative to the current working directory

what data structure does a shelf value resemble?

resembles a dictionary value; it has keys and values, along with keys() and values() that work similarly to the dictionary methods of the same names

What type of object is returned by requests.get()? How can you access the downloaded content as a string value?

returns a response object which has a text attribute that contains the downloaded content as a string

What does the search() method return?

returns match objects

What string methods can you use to right-justify, left-justify, and center a string?

rjust(), ljust(), and center() string methods

Example of saving a requests response to a file

saveFile = open('filename.html', 'wb') for chunk in res.iter_content(10000): saveFile.write(chunk)

what is a breakpoint?

setting on a line of code that causes the debugger to pause when the program execution reaches the line

say you have a Beautiful Soup Tag object stored in the variable spam for the element <div>Hello, world!<div>. How could you get a string 'Hello, world!' from the Tag object?

spam.getText()

What does an absolute path start with?

start with the root folder, such as / or C:\

how can you get the HTTP status code of a requests response?

status_code attribute of the Response object contains the HTTP status code

you could call send_keys(Keys.ENTER) on the Submit button's WebElement object, but what is an easier way to submit a form with Selenium?

submit() on any element within a form

what does the \t escape character represent

tab

what does passing re.VERBOSE as the second argument to re.compile() allow you to do?

the argument allows you to add whitespace and comments to the string passed to re.compile()

after you click continue, when will the debugger stop?

the debugger will stop when it has reached the end of the program or a line with a breakpoint

what does the . character match if re.DOTALL is passed as the second argument to re.compile()?

the dot will match any character even the newline character

What does Path('C:/Users' / 'Al') evaluate to on Windows?

the expression will cause an error because you cannot use the / operator to join two strings

What do the \d, \w, and \s shorthand character classes signify in regular expressions?

the shorthand character classes match a single digit, word, or space character

the string value "Howl's Moving Castle" is a valid string. Why isn't it a problem that the single quote character in the word Howl's isn't escaped?

the single quote is fine because the double quotes are used to mark the beginning and end of a string

If numRegex = re.compile(r'\d+'), what will numRegex.sub('X', '12 drummers, 11 pipers, five rings, 3 hens') return?

the sub() call will return the string 'X drummers, X pipers, five rings, X hens'

why is using logging messages better than using print() to display the same message?

you can disable logging messages without removing the logging function calls. You can create logging messages. Logging messages provide timestamps. You can selectively disable lower-level logging messages.

what is the difference between {3} and {3,5} in regular expressions?

{3} matches exactly three instances of the preceding group. the {3,5} matches between three and five instances


Ensembles d'études connexes

Real estate finance chapter 9 study questions, FIN3433 Test 2 Review, FIN3433 Test 2 Review, 3070 exam 2, Real Estate Ch 9 Quiz - Barker, chapter 9, FIN 351 chapter 9 quiz questions, Real Estate Final-Barker, FIN 3351 Chapter 10, REL 360 CH. 9, REE 3...

View Set

Programming Fundamentals 1: Exam 3 (Ch 7, 9, 10)

View Set

AP Gov Unit 4: Political Culture

View Set

Global Issues Section 1: Key Actors on the World Stage Quiz Questions

View Set

The Utilitarian John Stuart Mill

View Set

World Civ - The French Revolution

View Set

The Scientific Method Study Guide

View Set