Click here to Skip to main content
15,890,390 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
def GetLink():
                    URLs_all_Page = GetURL()
                    for Link_url in URLs_all_Page:
                        driver.get(Link_url)
                        time.sleep(2)

                        page_source = driver.page_source
                        soup = BeautifulSoup(page_source, "html.parser")

                        ExeName = soup.find('dt', {'class':'flex align-items-center'}).find('span', {'class':'profile-topcard-person-entity__name t-24 t-black t-bold'})
                        soup_ExeName = BeautifulSoup(ExeName.text, 'html.parser')
                        # print(soup_ExeName)1

                        PreCompany = soup.find('dd', {'class':'profile-topcard__previous-positions flex mt3'}).find('span', {'class':'t-14 t-black t-bold'})
                        if PreCompany is None:
                            PreCompany = soup.find('dd', {'class':'profile-topcard__previous-positions flex mt3'}).find('span', {'class':'align-self-center'}).find('a', {'class':'li-i18n-linkto inverse-link-on-a-light-background t-14 t-black t-bold'})
                            soup_PreCompany = BeautifulSoup(PreCompany.text,'html.parser')
                            # print(soup_PreCompany_a)

                        elif PreCompany is not None:
                            soup_PreCompany = BeautifulSoup(PreCompany.text,'html.parser')
                            # print(soup_PreCompany)

                        NewTitle = soup.find('span', {'class':'align-self-center'}).find('span', {'class':'profile-topcard__summary-position-title'})
                        soup_NewTitle = BeautifulSoup(NewTitle.text,'html.parser')
                        # print(soup_NewTitle)
                        
                        Company = soup.find('span', {'class':'align-self-center'}).find('span', {'class':'t-14 t-black t-bold'})    
                        if Company is None:
                            Company = soup.find('span', {'class':'align-self-center'}).find('a', {'class':'li-i18n-linkto inverse-link-on-a-light-background t-14 t-black t-bold'})
                            soup_Company = BeautifulSoup(Company.text, 'html.parser')
                            # print(soup_Company_a)

                        elif Company is not None:
                            soup_Company = BeautifulSoup(Company.text,'html.parser')
                            # print(soup_Company)
                            
                        tenur = soup.find('span', {'class':'align-self-center'}).find('span', {'class':'profile-topcard__time-period-bullet'})
                        soup_tenur = BeautifulSoup(tenur.text,'html.parser')
                        # print(soup_tenur)
                        
                        print(soup_ExeName,"|",soup_PreCompany,"|",soup_NewTitle,"|",soup_Company,"|",soup_tenur)
                    return Link_url
                print(GetLink())


What I have tried:

PreCompany = soup.find('dd', {'class':'profile-topcard__previous-positions flex mt3'}).find('span', {'class':'t-14 t-black t-bold'})
                        if PreCompany is None:
                            PreCompany = soup.find('dd', {'class':'profile-topcard__previous-positions flex mt3'}).find('span', {'class':'align-self-center'}).find('a', {'class':'li-i18n-linkto inverse-link-on-a-light-background t-14 t-black t-bold'})
                            soup_PreCompany = BeautifulSoup(PreCompany.text,'html.parser')
                            # print(soup_PreCompany_a)

                        elif PreCompany is not None:
                            soup_PreCompany = BeautifulSoup(PreCompany.text,'html.parser')
                            # print(soup_PreCompany)
Posted
Updated 7-Dec-21 21:01pm
v2
Comments
Richard MacCutchan 8-Dec-21 4:30am    
What is the problem and which line of code does it occur on?
Sriram Krishnamoorthy 2021 8-Dec-21 8:49am    
Thank You Richard !

The problem has shorted out Thank You once again.

#------------------------------------------------------------------------
if soup.find('dd', {'class':'profile-topcard__previous-positions flex mt3'}) is not None:
PreCompany = soup.find('dd', {'class':'profile-topcard__previous-positions flex mt3'}).find('span', {'class':'t-14 t-black t-bold'})
if PreCompany is None:
PreCompany = soup.find('dd', {'class':'profile-topcard__previous-positions flex mt3'}).find('span', {'class':'align-self-center'}).find('a', {'class':'li-i18n-linkto inverse-link-on-a-light-background t-14 t-black t-bold'})
soup_PreCompany = BeautifulSoup(PreCompany.text,'html.parser')
# print(soup_PreCompany_a)

elif PreCompany is not None:
soup_PreCompany = BeautifulSoup(PreCompany.text,'html.parser')
# print(soup_PreCompany)
elif soup.find('dd', {'class':'profile-topcard__previous-positions flex mt3'}) is None:
print("$Error Exception$")
Sriram Krishnamoorthy 2021 27-Dec-21 12:13pm    
Hi Richard,

I'm trying to save data in SSMS (SQL) but can't able to insert in DB.

The Error which I get - 'type' object is not subscriptable

----------------------Error Block---------------------------------------

cursor.execute(insert_statement, record)
except Exception as e:
cursor.rollback()
print(e)
print('Transaction Rolled Back')
----------------------Error Block---------------------------------------
----------------------code---------------------------------------

try:
records = [
[soup_ExeName, soup_PreCompany, soup_NewTitle, soup_Company, soup_tenur, soup_CRM]
]

DRIVER = 'SQL Server'
SERVER_NAME = 'SRIRAM\SQLEXPRESS'
DATABASE_NAME = 'DataSet'

Conn_string = f"""
Driver={{{DRIVER}}};
Server={SERVER_NAME};
Database={DATABASE_NAME};
Trust_Connection=yes;
"""

try:
Conn = odbc.connect(Conn_string)
except Exception as e:
print(e)
print('Task is Terminated')
sys.exit()
else:
cursor = Conn.cursor()

insert_statement = """
INSERT INTO RecordSet
VALUES (?, ?, ?, ?, ?, ?)
"""

try:
for record in records:
print(record)
cursor.execute(insert_statement, record)
except Exception as e:
cursor.rollback()
print(e)
print('Transaction Rolled Back')
else:
print('Record Inserted Sucessfully')
cursor.commit()
Conn.close()
finally:
if Conn.connected == 1:
print('Connection Closed')
Conn.close()

except Exception as e:
print(e)

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