MGMT 288 Exam 2 Book Questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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 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 is a breakpoint?

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

What data structure does a shelf value resemble?

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

What does an absolute path start with?

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

How do you save a requests response to a file?

After opening the new file on your computer in 'wb' "write binary" mode, use a for loop that iterates over the Response object's iter_content() method to write out chunks to the file. Here's an example: saveFile = open('filename.html', 'wb') for chunk in res.iter_content(100000): saveFile.write(chunk)

After you click Continue, when will the debugger stop?

After you click Continue, the debugger will stop when it has reached the end of the program or a line with a breakpoint.

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

An existing file opened in write mode is erased and completely overwritten.

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, while spam.txt is the base name.

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?

Calling the submit() method on any element within a form submits the form.

What are the five logging levels?

DEBUG, INFO, WARNING, ERROR, and CRITICAL

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

Either [0-9a-z] or [a-z0-9]

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 (that is, 'hello' and 'hello' are considered the same, and 'goodbye' and 'GOODbye' are also considered the same).

Either assert eggs.lower() != bacon.lower() 'The eggs and bacon variables are the same!' or assert eggs.upper() !=bacon.upper(), 'The eggs and bacon variables are the same!

What are escape characters?

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

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

F12 brings up the developer tools in Chrome. Pressing CTRL-SHIFT-C (on Windows and Linux) brings up the developer tools in Firefox.

.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, and group 2 covers the second set of parentheses

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.

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

Multiline strings allow you to use newlines in strings without the \n escape character.

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

On Windows, it evaluates to WindowsPath('C:/Users/Al'). On other operating systems, it evaluates to a different kind of Path object but with the same path.

How do you make a regular expression case-insensitive?

Passing re.I or re.IGNORECASE as the second argument to re.compile() will make the matching case insensitive.

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

Periods and parentheses can be escaped with a backslash: \., \(, and \).

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 a relative path relative to?

Relative paths are relative to the current working directory.

How can you view (in the developer tools) the HTML of a specific element on a web page?

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

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

The + matches one or more. The * matches zero or more.

What does the . character normally march? What does it match if re.DOTALL is passed as teh second argument to re.compile()? (don't need)

The . character normally matches any character except the newline character. If re.DOTALL is passed as the second argument to re.compile(), then the dot will also match newline characters.

What are the . and .. folders?

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

What is the difference between .* and .*?

The .* performs a greedy match, and the .*? performs a non-greedy match.

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

The ? character can either mean "match zero or one of the preceding group" or be used to signify non-greedy matching.

What does the I character signify in regular expressions?

The I character signifies matching "either, or " between two groups.

What are the differences between the Step Over, Step In and Step Out buttons in the debugger?

The Step In button will move the debugger into a function call. The Step Over button will quickly execute the function call without stepping into it. The Step Out button will quickly execute the rest of the code until it steps out of the function it currently is in.

What do the \D, \W, and \S shorthand character classes signify in regular expressions?

The \D, \W, and \S shorthand character classes match a single character that is not a digit, word, or space character, respectively.

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

The \\ escape character will represent a backlash character

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

The \d, \w, and \s shorthand character classes match a single digit, word, or space character, respectively.

What methods do Selenium's WebElement objects have for stimulating mouse clicks and keyboard keys?

The click() and send_keys() methods simulate mouse clicks and key board keys, respectively.

What does 'c:/Users' / 'Al' evaluate to on Windows?

The expression 'C:/Users' / 'Al' results in an error, since you can't use the / operator to join two strings.

What do the following expressions evaluate to? a. 'Hello'.upper() b. 'Hello'.upper(),isupper() c. 'Hello' upper().lower()

The expression evaluate to the following: a. 'HELLO' b. True c. 'hello'

What do the following expressions evaluate to? a. 'Hello, world!' [1] b. 'Hello, world!' [0:5] c. 'Hello, world!' [:5] d. 'Hello, world!' [3:]

The expressions evaluate to the following: a. 'e' b. 'Hello' c. 'Hello' d. 'lo, world!

What do the following expressions evaluate to? a. 'Remember, remember, the fifth of November.'.split() b. '-'.join('There can be only one.'.split())

The expressions evaluate to the following: a. ['Remember,', 'remember,' 'the', 'fifth', 'of', 'November.'] b. 'There-can-be-only-one.'

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

The find_element_* methods return the first matching element as a WebElement object. The find_elements_* methods return a list of all matching elements as WebElement objects.

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

The forward(), back(), and refresh() WebDriver object methods simulate these browser buttons.

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

The group() method returns strings of the matched text.

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

The lstrip() and rstrip() methods remove whitespace from the left and right ends of s string

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

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

What requests method checks that the download worked?

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

What does passing re.VERBOSE as the second argument to re.compile() allow you to do? (don't need)

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

What is the function that creates Regex objects?

The re.compile() function returns Regex objects.

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

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

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

The requests. get() function returns a Response object, which has a text attribute that contains the downloaded content as a string.

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

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

What does the search() method return?

The search() method returns Match objects.

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

The selenium module is imported with from Selenium import webdriver.

The string value "How'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 in Howl's is fine because you've used double quotes to mark the beginning and end of the string.

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

The status_code attribute of the Response object contains the HTTP status code.

What are the three "mode" arguments that can be passed to the open() function?

The string 'r' for read mode, 'w' for write mode, and 'a' for append mode.

If numRegex = re.compile(r'\d+'), what will numRegex.sub('X', '12 drummers, 11 pipers, five rings, 3 hens') return. (NEED STUFF WITH NUMBERS) (Don't need sub)

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

Briefly describe the differences between the webbrowser, requests, bs4 and selenium modules/

The webbrowser module has an open() method that will launch a web browser to a specific URL, and that's it. The requests module can download files and pages from the web. The BeautifulSoup module parses HTML. Finally, the selenium module can launch and control a browser.

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

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

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

To be able to call logging.degub(), you must have these two lines at the start of your program. import logging logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %levelname)s - %(message)s')

What are the two lines that your program must have in order to have logging.debug() send a logging message to a file named programLog.txt()?

To be able to send logging messages to a file named programLog.txt with logging.debug(), you must have these two lines at the start of your program: import logging >>> logging.basicConfig(filename= 'programLog.txt', level-logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')

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

To set a breakpoint in Mu, click the line number to make a red dot appear next to it.

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 selectively disable lower-level logging messages. You can create logging messages. Logging messages provide a timestamp.

What do the \n and \t escape characters represent?

\n is a newline; \t is a tab

Write an assert statement that always triggers an AssertionError.

assert False, 'This assertion always triggers.'

Write an assert statement that triggers an Assertion Error if the variable spam is an integer less than 10.

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

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 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? The regex should be case- insensitive. It must match the following: a. 'Alice eats apples.' b. 'Bob pets cats.' c. 'Carol throws baseballs.' d. 'Alice throws Apples.' e. 'BOB EATS CATS.' but not the following: a. 'RoboCop eats a[[les.' b. 'ALICE THROWS FOOTBALLS.' c. Carol eats 7 cats.'

re.compile(r'(AliceIBobICarol)\s(eatsIpetsIthrows)\s(applesIcatsIbasballs)\.', re.IGNORECASE)

How would you write a regex that matches the full name of someone whose last name is Watanabe? You can assume that the first name that comes before it will always be one word that begins with a capital letter. The regex must match the following: a. 'Haruto Watanabe' b. 'Alice Watanabe' c. 'RoboCop Watanabe' but not the following: a. 'haruto Watanabe' (where the first name is not capitalized) b. 'Mr. Watanabe' (where the precedng word has a nonletter character) c. 'Haruto watanabe' (where Watanabe is not capitalized)

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

How would you write a regex that matches a number with commas for every three digits? It must match the following: a. '42' b. '1,234' c. '6,368,745' but not the following: a. '12,34,567' (which has only two digits between the commas) b. '1234' (which lacks commas)

re.compile(r'^\d{1,3}(,\d{3})*$') will create this regex, but other regex strings can produce a similar regular expression.

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()


Kaugnay na mga set ng pag-aaral

Entrepreneurship 6.1 Review (Practice)

View Set

Intro to business chapter 16 Investment Opportunities in the Securities Market

View Set

Economic Applications Midterm, 1 Material

View Set

NCLEX LPN Pharmacological Parenteral Therapies

View Set