2021-12-12

Tech Programing

程式人小天地

unable to handle empty value in web scrapping

1 min read


I am scrapping a wiki. page, But there are some empty Table-data <td> in some rows, Therefor I used

for tr in table1.tbody:
list = []
for td in tr:
    try:
        if(td.text is None): list.append('NA')
        else: list.append(td.text.strip())
        
    except:
        list.append(td.strip())

to store those rows element in a list, But when i print row_list.
Those rows_list with empty value, which sould now have append ‘NA’ value , those are still empty, i;e ‘NA’ have not appended in list.
How could I fix this.

web page I am scrapping

code i have tried



Source link

資料來源:Stackoverflow

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *