Python BeautifulSoup scrape tables

后端 未结 3 1309
失恋的感觉
失恋的感觉 2020-12-13 10:05

I am trying to create a table scrape with BeautifulSoup. I wrote this Python code:

import urllib2
from bs4 import BeautifulSoup

url = \"http://dofollow.nets         


        
3条回答
  •  误落风尘
    2020-12-13 10:43

    # Libray
    from bs4 import BeautifulSoup
    
    # Empty List
    tabs = []
    
    # File handling
    with open('/home/rakesh/showHW/content.html', 'r') as fp:
        html_content = fp.read()
    
        table_doc = BeautifulSoup(html_content, 'html.parser')
        # parsing html content
        for tr in table_doc.table.find_all('tr'):
            tabs.append({
                'Nome': tr.find_all('td')[0].string,
                'Cogname': tr.find_all('td')[1].string,
                'Email': tr.find_all('td')[2].string
                })
    
        print(tabs)
    

提交回复
热议问题