Python Forum
Python html herf to json dump help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python html herf to json dump help
#1
please can you advise or help me on my code, the print out to the screen and csv works, but i would like a json outputfile
that can list all the /07-feb-2020/R1park-1400 /07-feb-2020/R2park-1530 /07-feb-2020/R3park-1600 with the beginning www.race.com/ so i can then import this in to another part of my program to run the next part of the scrape

thank you

import requests
from bs4 import BeautifulSoup
import csv
import json



#working links local
html_doc = open('D:\@users\python\raceing.html')

#example html doc
#
#href="/07-feb-2020/R1park-1400" class="winning">2:00</a></td><td
#
#href="/07-feb-2020/R2park-1530" class="winning">3:30</a></td><td
#
#href="/07-feb-2020/R3park-1600" class="winning">4:00</a></td><td
#
soup = BeautifulSoup(html_doc, 'html.parser')

link_set = set()
for link in soup.find_all('a',{'class' : 'winning'}):
    web_links = link.get("href")
    #links = [urljoin(start_url,['href'])  # convert relative url to absolute url
    print(web_links)
   # link_set.add(web_links)

csvfile = open('course.csv', 'w+', newline='')
writer = csv.writer(csvfile)
writer.writerow(['Links'])
for link in link_set:
    writer.writerow([link])
csvfile.close()


#working the json file where the output must be stored
html_doc = []
for url in html_doc:
    response = requests.get(url)
    url.append(res.text)
out_file = open("race.json", "w") 
  
json.dump(web_links,out_file, indent = 6)
out_file.close()
Reply


Messages In This Thread
Python html herf to json dump help - by paulfearn100 - Mar-03-2020, 09:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  JSON Dump and JSON Load foxholenoob 8 1,131 Oct-12-2023, 07:21 AM
Last Post: foxholenoob
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 939 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
  Python Split json into separate json based on node value CzarR 1 5,637 Jul-08-2022, 07:55 PM
Last Post: Larz60+
  reading html and edit chekcbox to html jacklee26 5 3,087 Jul-01-2021, 10:31 AM
Last Post: snippsat
  difficulties to chage json data structure using json module in python Sibdar 1 2,095 Apr-03-2020, 06:47 PM
Last Post: micseydel
  how json dump Japanese yunkai 2 8,129 Mar-17-2020, 07:06 AM
Last Post: vishalhule
  print python json dump onto multiple lines lhailey 2 19,892 Mar-02-2020, 12:47 PM
Last Post: vishalhule
  creating hex dump modifying program ensoniq 3 2,645 Oct-14-2019, 08:21 AM
Last Post: Larz60+
  HTML to Python to Windows .bat and back to HTML perfectservice33 0 1,955 Aug-22-2019, 06:31 AM
Last Post: perfectservice33
  Type error: dump() missing 1 required positional argument: fp jaycuff13 2 21,961 Jul-13-2019, 10:21 AM
Last Post: jaycuff13

Forum Jump:

User Panel Messages

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