logo
down
shadow

Beautifulsoup extract multiple lines


Beautifulsoup extract multiple lines

By : Klingon33333
Date : November 21 2020, 11:01 PM
To fix this issue I need some help and hope you can help me. , You need to iterate over the days:
code :
h = """<div><h2 class="week43"><a name="week43">Week 43</a></h2>
<div class="day"><h3 class="dayname">Monday</h3><div class="date">24/10/2016</div><div class="event" style="background-color: #58AA40"><a href="/course/view.php?id=16544">[E16] 1. sem / M1 - Psykiatri/psykologi</a><div class="teacher">Jane Doe</div><div class="time">Time: 08:15 - 12:00</div><div class="location">Location: KS5 lok. 47/49. GrpR:58,74,75,76,77,78,79,81,83</div><div class="note">Note: some notes</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">Jannie Doe</div><div class="time">Time: 08:15 - 10:00</div><div class="location">Location: NJV 6A 1.50</div><div class="note">Note: Hold X2 some notes</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">Jane Doe</div><div class="time">Time: 10:15 - 12:00</div><div class="location">Location: NJV 6A 1.50</div><div class="note">Note: Hold X2 - opsamling</div></div><div class="event" style="background-color: #58AA40"><a href="/course/view.php?id=16544">[E16] 1. sem / M1 - Psykiatri/psykologi</a><div class="teacher">Jannie Doe</div><div class="time">Time: 12:30 - 16:15</div><div class="location">Location: KS5 lok. 47/49.GrpR:58,74,75,76,77,78,79,81,83</div><div class="note">Note: some notes</div></div></div>
<div class="day"><h3 class="dayname">Tuesday</h3><div class="date">25/10/2016</div><div class="event" style="background-color: #5858FA"><a href="/course/view.php?id=16538">[E16] 1. sem / M1 - Socialt arbejde</a><div class="teacher">John Doe</div><div class="time">Time: 08:15 - 10:00</div><div class="location">Location: Fib 15. aud. B</div><div class="note">Note: Hold X&Y - Opsamling af profession og socialrådgiv</div></div><div class="event" style="background-color: #58AA40"><a href="/course/view.php?id=16544">[E16] 1. sem / M1 - Psykiatri/psykologi</a><div class="teacher">Jannie Doe</div><div class="time">Time: 10:15 - 14:15</div><div class="location">Location: NJV 8A, lok. 1.12 AUD</div><div class="note">Note: Hold X&Y - Perspektiver på psykiske lidelser...</div></div></div>
<div class="day"><h3 class="dayname">Wednesday</h3><div class="date">26/10/2016</div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">James Doe</div><div class="time">Time: 08:15 - 10:00</div><div class="location">Location: NJV 6A 1.50A</div><div class="note">Note: Hold Y1 - opsamling</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">James Doe</div><div class="time">Time: 10:15 - 12:00</div><div class="location">Location: NJV 6A 1.50A</div><div class="note">Note: Hold Y2 - opsamling</div></div></div>
<div class="day"><h3 class="dayname">Thursday</h3><div class="date">27/10/2016</div></div>
<div class="day"><h3 class="dayname">Friday</h3><div class="date">28/10/2016</div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">Johnny Doe</div><div class="time">Time: 08:15 - 10:00</div><div class="location">Location: Fib 13.053</div><div class="note">Note: Hold Y1a -  øvelser - opsamling</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">Lisa Andersen</div><div class="time">Time: 08:15 - 10:00</div><div class="location">Location: Fib 13.047</div><div class="note">Note: Hold X1a - øvelser - opsamling</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">John Doe</div><div class="time">Time: 08:15 - 10:00</div><div class="location">Location: Fib 13.049</div><div class="note">Note: Hold X2a -  øvelser - opsamling</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">Janine Doe</div><div class="time">Time: 08:15 - 10:00</div><div class="location">Location: Fib 13.055</div><div class="note">Note: Hold Y2a -  øvelser - opsamling</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">Jamie Doe</div><div class="time">Time: 10:15 - 12:00</div><div class="location">Location: Fib 13.047</div><div class="note">Note: Hold X1b -  øvelser - opsamling</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">James Doe</div><div class="time">Time: 10:15 - 12:00</div><div class="location">Location: Fib 13.055</div><div class="note">Note: Hold Y2b -  øvelser - opsamling</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">Johnny Doe</div><div class="time">Time: 10:15 - 12:00</div><div class="location">Location: Fib 13.053</div><div class="note">Note: Hold Y1b -  øvelser - opsamling</div></div><div class="event" style="background-color: #ACFA58"><a href="/course/view.php?id=16533">[E16] 1. sem / M1 - Jura</a><div class="teacher">John Doe</div><div class="time">Time: 10:15 - 12:00</div><div class="location">Location: Fib 13.049</div><div class="note">Note: Hold X2b -  øvelser - opsamling</div></div></div>
<div class="day"><h3 class="dayname">Saturday</h3><div class="date">29/10/2016</div></div>
<div class="day"><h3 class="dayname">Sunday</h3><div class="date">30/10/2016</div></div>
</div>
"""
from bs4 import BeautifulSoup
import re

soup = BeautifulSoup(h, "lxml")
for d in soup.find_all("div", class_="day"):
    notes = d.find_all("div", class_="note")
    teachers = d.find_all("div",class_="teacher")
    date = d.find("div", class_="date")
    times = d.find_all("div", class_="time")
    day = d.find("h3",class_="dayname")
    for note,time,   teacher in zip(notes,times,  teachers):
        note_text = note.text
        if "X2" in note_text:
            print((day.text, date.text, teacher.text,time.text, note.text))
('Monday', '24/10/2016', 'Jannie Doe', 'Time: 08:15 - 10:00', 'Note: Hold X2 some notes')
('Monday', '24/10/2016', 'Jane Doe', 'Time: 10:15 - 12:00', 'Note: Hold X2 - opsamling')
('Friday', '28/10/2016', 'John Doe', 'Time: 08:15 - 10:00', 'Note: Hold X2a -  øvelser - opsamling')
('Friday', '28/10/2016', 'John Doe', 'Time: 10:15 - 12:00', 'Note: Hold X2b -  øvelser - opsamling')
from csv import writer

with open("data.csv", "w") as f:
    wr = csv.writer(f)
    # write column names
    wr.writerow(["Day", "Date", "Teacher", "Note"])
    for d in soup.find_all("div", class_="day"):
        notes = d.find_all("div", class_="note")
        teachers = d.find_all("div",class_="teacher")
        date = d.find("div", class_="date")
        times = d.find_all("div", class_="time")
        day = d.find("h3",class_="dayname")
        for note,time,   teacher in zip(notes,times,  teachers):
            note_text = note.text
            if "X2" in note_text:
               # write each group on new row
                wr.writerow((day.text, date.text, teacher.text,time.text, note.text))


Share : facebook icon twitter icon
Extract lines from multiple text filenames and then pull those lines from a textfile - Linux

Extract lines from multiple text filenames and then pull those lines from a textfile - Linux


By : Greg Seamans
Date : March 29 2020, 07:55 AM
wish of those help My problem is I need to extract the line number from the end of a bunch of textfiles names with a size greater than 0. Once I have the list of line numbers, I need to extract the lines from the master text file. , Optimized and fast find solution:
code :
find . -type f -name "*.sh.e[0-9]*" -size +0c -exec sh -c 'fn=$1; n=${fn##*.}; \
        sed -n "$n p" ../temp/files.2017-09-26.txt' _ {} \;
Python - BeautifulSoup extract value from multiple options

Python - BeautifulSoup extract value from multiple options


By : prasad
Date : March 29 2020, 07:55 AM
With these it helps Code: , You can use the name parameter in the find call:
code :
from bs4 import BeautifulSoup as soup
print(soup(html, 'html.parser').find('input', {'name':"CSRFToken"})['value'])
80f1330a-7a4e-4878-a6ab-710356f47961
python beautifulsoup search across multiple lines

python beautifulsoup search across multiple lines


By : nakula
Date : March 29 2020, 07:55 AM
I wish this help you I am trying to search for the P/E ratio of a finance page, from the input code shown below. So, essentially I am trying to extract '48.98' from the source. As the structure is same for Market cap, book value, etc. I am unable to frame the correct code for a soup.find , Use the text to find the div with "P/E" and get the next div:
How to remove multiple empty lines when scraping with Beautifulsoup

How to remove multiple empty lines when scraping with Beautifulsoup


By : Nicolas Stampf
Date : March 29 2020, 07:55 AM
Hope that helps my code outputs multiple empty line breaks. How do i remove all the empty space? , You could remove empty lines before printing:
code :
items = [item.text for item in all if item.text.strip() != '']
How to extract only specific string matching lines from a multiple lines standard input

How to extract only specific string matching lines from a multiple lines standard input


By : ABI
Date : October 16 2020, 06:10 PM
will be helpful for those in need No magic required - save the values in an array when they're seen in the input and print them when you hit a --- line:
code :
$ awk -F'=' -v OFS=',' '/---/{print v["fruit"], v["car"]} {v[$1]=$2}' file
apple,bmw
orange,ford
Related Posts Related Posts :
  • STM32 internal clocks
  • OrientDB callback after record is persisted in server
  • Position of scaling points
  • Limit nested objects results in rethinkdb query
  • Outlook REST API Push Notification always send the same ResourceData
  • OBIEE Recipients can't see all other recipients of a sent email
  • Hex Encoding and Decoding
  • Why do the bindings on my Orchestration change when I install an msi?
  • Vuejs 2 + splice
  • ImageMagick - Drawing a complex image with many (lots of) squares
  • Get specific property of a model returns error: Undefined property: Illuminate\Database\Eloquent\Builder::$id
  • Installing brew on Mac 10.6 results in syntax error
  • How to create a google map from information contained in a database
  • How can I upgrade to CocoaPods 1.1 when it has been released now?
  • Not able to install plugins in latest openmdao 1.7.x
  • Skype SDK Conversation Control - Leaving a Conversation
  • Retrieving camera recordings via ONVIF
  • how to fetch JSON dictionary/array with Alamofire 4.0 and show it on tableView Cell
  • How to upload (Best way to upload) whole OctoberCMS project from localhost to live server
  • Wait for set of emmisions to occur in Observable
  • Link Carousel slider with navigation bar
  • Set work profile using wso2 agent app android
  • Kentico 9 - How to get assigned role info or name to a document
  • Making HTTP POST call using Gupshup's bot builder tool
  • Purescript - Unable to build with drawing and signals libraries
  • Unable to count the number of rows in BigTable
  • How to get an Erlang app to run at starting rebar3
  • varnish referencing an external file
  • What's the Transport Protocol for MessagePack / Protocol Buffers?
  • React-Bootstrap add pull-right to Button
  • Spring Integration Kafka Configuration - Errors in Eclipse
  • Modify Source Observable on retry - RxJava
  • False Error: A constructor name should not start with a lowercase letter babel/new-cap
  • configuration options used in ubuntu 16 apache2 package
  • Use Undertwo web server to serve both static pages and web service
  • tasm 1.4 color code orange instead of yellow
  • Calculating time complexity using master method
  • "Re-enabling" App Authenticity in Mobilefirst 8.0 not working
  • Two steps search to search document with similar vectors in Solr
  • What is the Big-O of this nested loop?
  • Why I'm not getting the params in activate method?
  • Check which side one rectangle collide with other
  • Where is record getting defined in the _master template default theme?
  • How to work around self borrowing with map .or_insert_with? Rust (1.11)
  • Strings that {b U a}* Accepts (Kleene Star)
  • GeoJSON layer won't load on MapBox GL JS
  • Difference between two expressions in Alloy?
  • How To Use NSNotificationCenter In Sierra
  • FreeBSD pkg suddenly stopped bootstrapping
  • Request a Blockchain API V2 to receive Payments
  • Hide the catalog page on Shopify
  • LLVM alignment of nested structs/arrays
  • A default parent router with child routers
  • grunt-mocha: PhantomJS timed out, possibly due to a missing Mocha run() call
  • is it ok to use the exports keyword with commonjs - webpack 1
  • When doing a compare, why must I cast an unsigned to avoid warnings
  • An algorithm that determines if a function f from the finite set A to the finite set B is an onto function.
  • CIL / MSIL Boxing issue?
  • How to provide default url for mvcSiteMapNodes
  • Can an Action use bindFromRequest() method without no submitting?
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com