Mar-22-2020, 06:22 AM
Hello Python Web Scraping Coders,
I am trying to determine how to write the 3 columns that I parse from HTML URL and send to a CSV; also / or directly into a MySQL (MariaDB) Database.
I have successfully loaded a working mysql.connector into my existing Python3 script and it connects to my Database Successfully! I have never gotten this far until now.
Below is my code and any tips in the right direction would be greatly appreciated!
Current Python3 Code:
Best Regards,
Brandon Kastning
P.S. - May your families be safe! God bless!
I am trying to determine how to write the 3 columns that I parse from HTML URL and send to a CSV; also / or directly into a MySQL (MariaDB) Database.
I have successfully loaded a working mysql.connector into my existing Python3 script and it connects to my Database Successfully! I have never gotten this far until now.
Below is my code and any tips in the right direction would be greatly appreciated!
Current Python3 Code:
from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen("http://law.justia.com/cases/federal/appellate-courts/F2/999/663/308588/") bsObj = BeautifulSoup(html.read()) allOpinion = bsObj.findAll(id="opinion") import requests from bs4 import BeautifulSoup url = "http://law.justia.com/cases/federal/appellate-courts/F2/999/663/308588/" allTitle = bsObj.findAll({"title"}) allURL = url print(allOpinion) print(allTitle) print(allURL) import csv csvRow = [allOpinion,allTitle,allURL] csvfile = "current_F2_opinion_with_tags_current.csv" with open(csvfile, "a") as fp: wr = csv.writer(fp, dialect='excel') wr.writerow(csvRow) print(allOpinion[0].get_text(),url) import csv csvRow = [allOpinion[0].get_text(),allTitle[0].get_text(),allURL] csvfile = "current_F2_opinion_without_tags_current.csv" with open(csvfile, "a") as fp: wr = csv.writer(fp, dialect='excel') wr.writerow(csvRow) import mysql.connector from mysql.connector import Error try: connection = mysql.connector.connect(host='localhost', database='PythonMariaDB1', user='PythonMariaDB1', password='password1234') if connection.is_connected(): db_Info = connection.get_server_info() print("Connected to MySQL Server version ", db_Info) cursor = connection.cursor() cursor.execute("select database();") record = cursor.fetchone() print("You're connected to database: ", record) except Error as e: print("Error while connecting to MySQL", e) finally: if (connection.is_connected()): cursor.close() connection.close() print("MySQL connection is closed")Thank you!
Best Regards,
Brandon Kastning
P.S. - May your families be safe! God bless!
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)
“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)
#LetHISPeopleGo
“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)
#LetHISPeopleGo