Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON PROGRAMMING: FILL IN QUESTION MARKS/YOUR CODE HERE Question no. 14: In this section you are going to use some advance web-scrapping ideas. However you

PYTHON PROGRAMMING: FILL IN QUESTION MARKS/"YOUR CODE HERE"

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. [5 x 3 = 15 points]

import urllib3 from bs4 import BeautifulSoup import urllib3 import random

# Please do not feel confused with following 4 lines of code # These codes just grab all the html content from website # And we get all the image tag in a list called tags in line 11 http = urllib3.PoolManager() r = http.request('GET', 'https://www.boredpanda.com/funniest-two-line-jokes/?utm_source=google&utm_medium=organic&utm_campaign=organic') soup = BeautifulSoup(r.data) tags=soup.findAll('img')

# Lets see how these tags look like, we are looking only 10 examples random.sample(tags,10)

# lets grab first item of these tags and see its type # You will find it is not a 'str' but something else type(tags[0])

# type = bs4.element.Tag

# Now you have to map these tags to string with the following lambda operation tostr = lambda x:str(x) tags = ? # your code here

# After we mapped everything to string we still need to get specific tags # Use following lambda operation to filter getjokes = lambda x:'funniest-two-line-jokes' in x tags = [*filter(?)] # your code here

# You don't have to do anything here # If you got everything right # You can run this cell as many times as you like # and read wonderful jokes # Disclaimer : These jokes are grabbed from internet, take it easy

from PIL import Image import requests from io import BytesIO import random random.seed()

response = requests.get(random.choice(tags)) Image.open(BytesIO(response.content))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions