Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python 3 questions + Code + Text Question no. 14: In this section you are going to use some advance web-scrapping ideas. However you don't
python 3 questions
+ Code + Text Question no. 14: In this section you are going to use some advance web-scrapping ideas. However you don't have to code anything for that. But you have to post-process the content you get from the internet. This processing includes mapping - filtering and mapping task. This exercise is followed by a given code snippet which rewards you for your hard work. 5x3= 15 points) research (1 I hope you will learn something new here TE you feel anything confusing please do # I am not going through all the details here Import 3 from bat import Beautiful Soup LIPO 3 Laport random # Please do not feel confused with following 4 lines of code # These codes o grab all the html content from website # And we get all the image tag in a list called tags in line 11 http- ur . Pool Manager - http.reques (CET. https boredana com funniestelinee soup - Rautiful soupidata) tagsp.tidalling" t g ooglebut medic emples #Lets see how these tags look like we are looking only 10 random sample(tags, 10) leta grab first item of these tags and see wype # You will find it is nos " E' but something else type (bags (0) ing with the following lambida operation # Now you have to map these tage to s COSE - Landa tage- p(751. Complete the code After we mapped everything to string we still need to get speeitse tags Use following laws operation to filter getoke-lambda funniest-to-i -jokes tags = ter(231 [] Now we need only the link to the joke not a full tag # use following map to map the tag inte link filterer - Lamoda NIK. partition ( SEO )-1) partition tag a p() Now there is the fun part You don't have to do anything here . If you you verything right . You can run this coll many times you like and read wonderful Jokes Dili These jokes are grabbed tre interes take from PIL pors Tage port requests from toport Bytesto Endomsad() - Dictionary 1 Dictionary is an interesting data structu # It holds key value pairs # Values can be accessed by using keys # Lets see few of the ways to create a dictionary a = {'a': 'b':2, print('a : {a}') 'e':3, 'd' :4) b- diet (zip (['a', 'b', 'c' print ( b: {b}') (1,2,3, c = dict(iter(l'a, 1), ('b', 2), t'e',3), ('a', print('c : {c}"? d - dict(a=1, b=2, -3, d-4) 2. -3. d-4) print it'd : (d)) + Accessing values using keys in dictionary print (d'altgetting values corresponding to key # Study the following code closely + Here is a function that returns a value # given a key and a dictionary as arguments # For now you don't have to know the details of # how to define a function # A very simple function def get from (dictionary, keys): values - dictionary keya) return values 11 . Now lets use this function to get values corresponding + trom dictionary "d values - get from (dictionary, 'd', keys='a') print 'values correspoding to a 1s (values)) return values TypeError Traceback (most recent call last) Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started