Scrape tables into dataframe with BeautifulSoup

后端 未结 4 872
日久生厌
日久生厌 2020-12-13 21:03

I\'m trying to scrape the data from the coins catalog.

There is one of the pages. I need to scrape this data into Dataframe

So far I have this code:

<
4条回答
  •  半阙折子戏
    2020-12-13 21:30

    Just a head's up... This part of Rakesh's code means that only HTML rows containing text will be included in the dataframe, as the rows don't get appended if row is an empty list:

    if row:
        res.append(row)
    

    Problematic in my use case, where I wanted to compare row indexing for the HTML and dataframe tables later on. I just needed to change it to:

    res.append(row)
    

    Also, if a cell in the row is empty, it doesn't get included. This then messes up the columns. So I changed

    row = [tr.text.strip() for tr in td if tr.text.strip()]
    

    to

    row = [d.text.strip() for d in td]
    

    But, otherwise, it's working for me. Thanks :)

提交回复
热议问题