mardi 28 septembre 2021

extract word from after scrapping with BeautifulSoup

I had gathered some infos using BeautifulSoup4 in the webpage: https://www.peakbagger.com/list.aspx?lid=5651

from urllib.request import urlopen
from bs4 import BeautifulSoup
import pandas as pd

url = 'https://www.peakbagger.com/list.aspx?lid=5651'
html = urlopen(url)
soup = BeautifulSoup(html, 'html.parser')

row = soup.find('tr') 
row

rows = soup.find_all('tr')
for row in rows:          
    print(row.get_text())

I would want to print the word so that each can be shown in each different sections, e.g.

before:

1.Fuji-sanKanto3776Yamanashi-ken/Shizuoka-kenHonshu3776318

2.Kita-dakeChubu3192Yamanashi-kenHonshu223731

after:

(a= )

Fuji-san

Kita-dake

...

(b=)

Kanto

Chubu

...

(c=)

3776

3192

...

for every of the lines starting from 1. to 100.

Shall I use a for loop or split to break each word?

Thank you.




Aucun commentaire:

Enregistrer un commentaire