Click here to Skip to main content
15,302,455 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
I am trying to insert table data in excel file column wise in which left side tab must be column name and right side data in rows

SKU	                       07DE9922
Analyte / Target	       Corticosterone
Base Catalog Number	       DE9922
Diagnostic Platforms	   EIA/ELISA
Diagnostic Solutions	   Endocrinology
Disease Screened	       Corticosterone
Evaluation	               Quantitative
Pack Size	               96 Wells
Sample Type	               Plasma, Serum
Sample Volume	           10 uL
Species Reactivity	       Mouse, Rat
Usage Statement	           For Research Use Only, not for use in diagnostic procedures.

What I have tried:

from bs4 import BeautifulSoup
import pandas as pd
import requests
import time
from datetime import datetime

def extract_source(url):
     agent = {"User-Agent":"Mozilla/5.0"}
     source=requests.get(url, headers=agent).text
     return source

html_text = extract_source('')
soup = BeautifulSoup(html_text, 'lxml')

for a in soup.find_all('a', class_ = 'button button--link button--fluid catalog-list-item__actions-primary-button', href=True):
    # print ("Found the URL:", a['href'])
    urlof = a['href']
    html_text = extract_source(urlof)
    soup = BeautifulSoup(html_text, 'lxml') 
    table_rows = soup.find_all('tr')

    first_columns = []
    third_columns = []
    for row in table_rows:
#         for row in table_rows[1:]:

    for first, third in zip(first_columns, third_columns):
        #print(first.text, third.text)
        print(third.text, sep=' ', end='', flush=True)
Updated 11-Apr-21 3:04am
Richard MacCutchan 11-Apr-21 3:30am
And? Do you have a question?
SeanChupas 13-Apr-21 9:14am
What is your question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900