Last active
October 24, 2022 16:31
-
-
Save crbyxwpzfl/b6d5c50121956d5847f55179119efceb to your computer and use it in GitHub Desktop.
webscraper tries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from msedge.selenium_tools import Edge, EdgeOptions | |
from bs4 import BeautifulSoup | |
from selenium import webdriver | |
import requests | |
import json | |
options = EdgeOptions() | |
options.use_chromium = True | |
#options.add_argument("headless") | |
#options.add_argument("disable-gpu") | |
driver = Edge("C:/Users/roess/Downloads/edgedriver_win64/msedgedriver.exe", options = options) | |
try: | |
SCROLL_PAUSE_TIME = 10 | |
driver.get("https://music.apple.com/de/playlist/wei%C3%9F-nicht/pl.u-6mo4ayKuBqYYXWj") | |
time.sleep(10) | |
last_height = driver.execute_script("return document.body.scrollHeight") | |
while True: | |
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") | |
time.sleep(SCROLL_PAUSE_TIME) | |
new_height = driver.execute_script("return document.body.scrollHeight") | |
if new_height == last_height: | |
break | |
last_height = new_height | |
soup = BeautifulSoup(driver.page_source, "html.parser") | |
song = soup.findAll('div', class_='song-wrapper two-lines') | |
dataArr= [] | |
for container in song: | |
SongsObject ={ | |
"name": container.find('div', class_='song-name typography-label').text.replace('\n',''), | |
"interpret": container.find('div', class_='by-line typography-caption').text.replace('\n','') | |
} | |
print(SongsObject) | |
dataArr.append(SongsObject) | |
with open("C://Users/roess/Desktop/Neuer Ordner/Data.json", 'w') as outfile: | |
json.dump(dataArr, outfile) | |
finally: | |
driver.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import requests | |
url = "https://music.apple.com/de/playlist/for-michi/pl.u-AkAm8qpF2JMMqEo" | |
results = requests.get(url) | |
soup = BeautifulSoup(results.text, "html.parser") | |
#print(soup.prettify()) | |
song = soup.findAll('div', class_='song-wrapper two-lines') | |
#print(song) | |
for container in song: | |
#name = container.text | |
#print(name) | |
SongsObject ={ | |
"name": container.find('div', class_='song-name typography-label').text, | |
"interpret": container.find('div', class_='by-line typography-caption').text | |
} | |
print(SongsObject) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"name": "Gold Lion", "interpret": "Yeah Yeah Yeahs "}, {"name": "Ready or Not", "interpret": "Milk & Sugar "}, {"name": "R U Mine?", "interpret": "Arctic Monkeys "}, {"name": "Why'd You Only Call Me When You're High?", "interpret": "Arctic Monkeys "}, {"name": "Arabella", "interpret": "Arctic Monkeys "}, {"name": "Breezeblocks", "interpret": "alt-J "}, {"name": "Left Hand Free", "interpret": "alt-J "}, {"name": "Something Good", "interpret": "alt-J "}, {"name": "Hunger of the Pine", "interpret": "alt-J "}, {"name": "Gold", "interpret": "Chet Faker "}, {"name": "Fiction", "interpret": "The xx "}, {"name": "Howling (\u00c2me Remix)", "interpret": "Howling "}, {"name": "Toes", "interpret": "Glass Animals "}, {"name": "Gooey", "interpret": "Glass Animals "}, {"name": "Pools", "interpret": "Glass Animals "}, {"name": "Hazey", "interpret": "Glass Animals "}, {"name": "Hypnotise", "interpret": "Polarheart "}, {"name": "You Hear Colours", "interpret": "CFCF "}, {"name": "So Long", "interpret": "Abstract, Cam Meekins & Dave Mac "}, {"name": "Tubthumping", "interpret": "Chumbawamba "}, {"name": "River", "interpret": "Bishop Briggs "}, {"name": "Wild Horses", "interpret": "Bishop Briggs "}, {"name": "The Way I Do", "interpret": "Bishop Briggs "}, {"name": "Can't Hold Me Down (feat. Tash Neal)", "interpret": "GRiZ "}, {"name": "Born Ready", "interpret": "Zayde W\u00f8lf "}, {"name": "Gone with the Wind (feat. Ben Webster)", "interpret": "Art Tatum "}, {"name": "Sirens", "interpret": "Rag'n'Bone Man "}, {"name": "I'm Ready", "interpret": "AJR "}, {"name": "Deadcrush", "interpret": "alt-J "}, {"name": "Borderline", "interpret": "Tove Styrke "}, {"name": "Swing That Music (Live)", "interpret": "Wycliffe Gordon "}, {"name": "MIC Drop", "interpret": "BTS "}, {"name": "Gone", "interpret": "Bazzi "}, {"name": "Louie Louie", "interpret": "Iggy Pop "}, {"name": "Underdog (Live at King Power Stadium)", "interpret": "Kasabian "}, {"name": "Blood // Water", "interpret": "grandson "}, {"name": "Best Friends", "interpret": "grandson "}, {"name": "Dirty Love", "interpret": "Mt. Joy "}, {"name": "Murder to Excellence", "interpret": "JAY-Z & Kanye West "}, {"name": "L.E.S. Artistes", "interpret": "Santigold "}, {"name": "Maybe You Love Me (feat. Mike Posner)", "interpret": "Riff Raff "}, {"name": "Gypsy Woman (She's Homeless) [Radio Mix]", "interpret": "Crystal Waters "}, {"name": "Wash Your Face in My Sink", "interpret": "Dream Warriors "}, {"name": "Dub Be Good to Me", "interpret": "Beats International "}, {"name": "Anything Goes", "interpret": "NVDES "}, {"name": "All In", "interpret": "The Palms "}, {"name": "Lou\u00ec", "interpret": "NVDES "}, {"name": "Do You Think About Me", "interpret": "NVDES "}, {"name": "The Other Side", "interpret": "NVDES "}, {"name": "Better Places (feat. Nvdes)", "interpret": "Pierce Fulton "}, {"name": "BoJack\u2019s Theme (Full Length) [feat. Ralph Carney]", "interpret": "Patrick Carney "}, {"name": "Tony the Ibm", "interpret": "Eric Serra "}, {"name": "Water Flow", "interpret": "Klyne "}, {"name": "Sit Back (feat. Truthos Mufasa & Black Josh)", "interpret": "The Mouse Outfit "}, {"name": "Delancey", "interpret": "Tidus "}, {"name": "Burn It (feat. Ocean Wisdom)", "interpret": "Fliptrix "}, {"name": "See You There", "interpret": "Tidus "}, {"name": "Get It Right", "interpret": "Tidus "}, {"name": "Before It's Too Late", "interpret": "Tidus "}, {"name": "Without a Care", "interpret": "Tidus "}, {"name": "My Energy", "interpret": "Tidus "}, {"name": "Powers", "interpret": "Tidus "}, {"name": "It's Yours", "interpret": "Tidus "}, {"name": "FYTB", "interpret": "Tidus "}, {"name": "On God", "interpret": "Tidus "}, {"name": "Escalators", "interpret": "Tidus "}, {"name": "Without a Care", "interpret": "Tidus "}, {"name": "Seams", "interpret": "Tidus "}, {"name": "B.O.B. (Bombs Over Baghdad)", "interpret": "OutKast "}, {"name": "The Kids", "interpret": "Sol "}, {"name": "Wheels", "interpret": "josh pan & Dylan Brady "}, {"name": "Vacation", "interpret": "Dirty Heads "}, {"name": "Tokyo Drifting", "interpret": "Glass Animals & Denzel Curry "}, {"name": "Upside Down (feat. Grouplove)", "interpret": "Whethan "}, {"name": "Kathleen", "interpret": "Catfish and the Bottlemen "}, {"name": "Sex With Exes", "interpret": "Matt Easton "}, {"name": "Suavemente (Merengue)", "interpret": "Elvis Crespo "}, {"name": "Love Is a Battlefield", "interpret": "Pat Benatar "}, {"name": "Oh Mama", "interpret": "Milky Chance "}, {"name": "Vivaldi", "interpret": "Faber "}, {"name": "The Gambler (feat. Anthony Hamilton)", "interpret": "Xzibit featuring Anthony Hamilton "}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment