I have several values scraped from a website, and I wanna covert to dataframe like:
dates titles links
2021-05-13 AAA https
I use:
html_link = 'https://www.ksei.co.id/publications/new-securities-registration?setLocale=en-US'
html = requests.get(html_link).text
soup = BeautifulSoup(html, 'html.parser')
titles = []
links = []
dates = []
for ultag in soup.find_all('ul', {'class': 'list-nostyle'}):
for litag in ultag.find_all('li'):
for dates in litag.find_all('small', {'class': 'muted'}):
title = litag.find('h2', {'class': 'h4 no-margin'})
link = litag.find('a', href=True)
titles.append(title.text)
links.append(f"https://www.pds.com.ph{link['href']}")
dates.append(dates.text)
#print(titles,links,dates)
dataframe = pd.DataFrame(zip(titles, links, dates), columns=['Titles', 'Links', 'Dates'])
print(dataframe)
But it only returns the first two rows, no idea why. I am confused with zip function, and always stuck with the lists to dataframe...
Thanks for the help in advance!
