Mixed-Up Code Questions¶
Create a function called img_links
that takes in a parameter url
and returns a list of all urls for all the images on the page.
Since websites are frequently updated, the returned list of image links may change as image links get added and deleted.
Write a function called img_links
that takes in a parameter url
and returns a list of all urls for all the images on the page.
Since websites are frequently updated, the returned list of image links may change as image links get added and deleted.
Create a function called shapiro_link
that takes in a parameter url
and returns the URL from the University of Michigan wikipedia page that links to the Shapiro Undergraduate Library.
For example, shapiro_link('https://en.wikipedia.org/wiki/University_of_Michigan')
should return "https://en.wikipedia.org/wiki/Shapiro_Undergraduate_Library"
.
Write a function called shapiro_link
that takes in a parameter url
and returns the URL from the University of Michigan wikipedia page that links to the Shapiro Undergraduate Library.
For example, shapiro_link('https://en.wikipedia.org/wiki/University_of_Michigan')
should return "https://en.wikipedia.org/wiki/Shapiro_Undergraduate_Library"
.
Create a function called link_or_none
that takes in a parameter url
and returns a list of all the links in the a tags
that are in a div tag
with the class column
and id news-items
. If there isn’t a link in the a tag
that’s in a div tag
with the class column
and id news-items
, have None take its place in the list. Since websites are frequently updated,
the returned list of links may change as links get added and deleted.
Write a function called link_or_none
that takes in a parameter url
and returns a list of all the links in the a tags
that are in a div tag
with the class column
and id news-items
. If there isn’t a link in the a tag
that’s in a div tag
with the class column
and id news-items
, have None take its place in the list. Since websites are frequently updated,
the returned list of links may change as links get added and deleted.
Create a function called descriptions
that takes in parameters base_url
and endings
and returns a dictionary with each ending as keys and their description as values. For this question,
get a soup from each URL with an ending from endings
, get the first div tag
with class = 'body wysiwyg-content'
,
and then extract the text from the first paragraph. That text will be the description for the dictionary value.
For example, as of 2021, descriptions('https://www.si.umich.edu/programs/courses/', ['106', '206', '330'])
should return
{'106': 'Introduction to programming with a focus on applications in informatics. Covers the fundamental elements of a modern programming language and how to access data on the internet. Explores how humans and technology complement one another, including techniques used to coordinate groups of people working together on software development.', '206': 'Students develop their core programming and software development skills, to build competency and literacy in important areas that includes basic data structures, debugging and testing, using distributed code repositories, pattern matching, and programmatic gathering and processing of data. Applications in assignments and labs are oriented around data manipulation.', '330': "Data analysis is crucial to application evaluation, as well as understanding users' information needs. When the data required are numerous we need an automated way to gather, parse, and summarize the data. In this course, you will learn to use Python and its modules to accomplish these tasks."}
.
Write a function called descriptions
that takes in parameters base_url
and endings
and returns a dictionary with each ending as keys and their description as values. For this question,
get a soup from each URL with an ending from endings
, get the first div tag
with class = 'body wysiwyg-content'
,
and then extract the text from the first paragraph. That text will be the description for the dictionary value.
For example, as of 2021, descriptions('https://www.si.umich.edu/programs/courses/', ['106', '206', '330'])
should return
{'106': 'Introduction to programming with a focus on applications in informatics. Covers the fundamental elements of a modern programming language and how to access data on the internet. Explores how humans and technology complement one another, including techniques used to coordinate groups of people working together on software development.', '206': 'Students develop their core programming and software development skills, to build competency and literacy in important areas that includes basic data structures, debugging and testing, using distributed code repositories, pattern matching, and programmatic gathering and processing of data. Applications in assignments and labs are oriented around data manipulation.', '330': "Data analysis is crucial to application evaluation, as well as understanding users' information needs. When the data required are numerous we need an automated way to gather, parse, and summarize the data. In this course, you will learn to use Python and its modules to accomplish these tasks."}
.
Create a function called url_links
that takes in a parameter url
and returns a list of all url links from the url
.
Since websites are frequently updated, the returned list of links may change as links get added and deleted.
Write a function called url_links
that takes in a parameter url
and returns a list of all url links from the url
.
Since websites are frequently updated, the returned list of links may change as links get added and deleted.
Create a function called bsoup_num_links
that takes in a parameter url
and returns the number of ‘href’
attributes that start with ‘http’ using BeautifulSoup. Since websites are frequently updated,
the returned number may change as links get added and deleted.
Write a function called bsoup_num_links
that takes in a parameter url
and returns the number of ‘href’
attributes that start with ‘http’ using BeautifulSoup. Since websites are frequently updated,
the returned number may change as links get added and deleted.
Create a function called img_links
that takes in a parameter url
and returns a list that contains all image links
using BeautifulSoup. Since websites are frequently updated, the returned list of image links may change as image links get added and deleted.
Write a function called img_links
that takes in a parameter url
and returns a list that contains all image links
using BeautifulSoup. Since websites are frequently updated, the returned list of image links may change as image links get added and deleted.
Create a function called span_attrs
that takes in a parameter url
and returns a list of dictionaries using BeautifulSoup.
Each dictionary is equivalent to each span tag. The keys of the dictionary are the attributes of the span tag,
and the values of the dictionary are the values of the attributes. Since websites are frequently updated,
the returned list of dictionaries may change as span tags, attributes, and values get added, deleted, or modified.
Write a function called span_attrs
that takes in a parameter url
and returns a list of dictionaries using BeautifulSoup.
Each dictionary is equivalent to each span tag. The keys of the dictionary are the attributes of the span tag,
and the values of the dictionary are the values of the attributes. Since websites are frequently updated,
the returned list of dictionaries may change as span tags, attributes, and values get added, deleted, or modified.