Python Forum
from List to BeautifulSoup , Homework
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
from List to BeautifulSoup , Homework
#1
Hello everyone, I hope not to be annoying.
I am taking basic python lectures and I have a homework where I am asked to return a Json Dump of some information i have to look from 4 pages (html files)

I need to write a function but they give me a code that i am not allowed to modify:

with open('GivenPage.htm') as f:
    file1 = f.readlines()
With this code i have to write a function( in my notebook for python) to look for information and return a Json dump
def MyFunction(file1):
    import json
    import requests
    from bs4 import BeautifulSoup
    
   print(type(file1))
   print(file1)
    
First i printed to see what information i had:
# I go a list type
# I got the list html, example...
####
<class 'list'>
['<!DOCTYPE html><html><head><script>(function(){(function(){function e(a){this.t={};this.tick=function(a,c,b){var d=void 0!=b?b:(new Date).getTime();this.t[a]=[d,c];if(void 0==b)try{window.console.timeStamp("CSI/"+a)}catch(h){}};this.tick("start",null,a)}var a;if(window.performance)var d=(a=window.performance.timi

#####


So i decided to convert my list into a BeatifulSoup in order to be able to use .find_all and .find , to look for the nested tags, but as i did not find anything online to convert, i decided to convert it into a string and then try to convert the string into beautiful soup
NewString="".join(file1)
But right now i feel i bit stuck, I am looking online for finding a way, but meanwhile, I would like to know if you know a manner.

Thanks for your time.
I really do not want to be annoying.

Wall
Reply


Messages In This Thread
from List to BeautifulSoup , Homework - by RPC - Jul-02-2018, 05:27 AM
RE: from List to BeautifulSoup , Homework - by RPC - Jul-02-2018, 05:44 AM
RE: from List to BeautifulSoup , Homework - by RPC - Jul-02-2018, 02:32 PM
RE: from List to BeautifulSoup , Homework - by RPC - Jul-02-2018, 07:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python BeautifulSoup IndexError: list index out of range rhat398 1 6,248 May-28-2021, 09:09 PM
Last Post: Daring_T
  Getting 'list index out of range' while fetching product details using BeautifulSoup? PrateekG 8 8,179 Jun-06-2018, 12:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020