【爬虫】bs4新发地

# -*- coding:utf-8 -*-

import requests
import csv
from bs4 import BeautifulSoup

url = "http://www.xinfadi.com.cn/priceDetail.html"
resp = requests.get(url)

page = BeautifulSoup(resp.text, "html.parser")

thd = page.find("thead")

trs = thd.find_all("tr")[1:]

for tr in trs:
    ths = tr.find_all("th")

    first = ths[0].text
    second = ths[1].text
    name = ths[2].text

    print(first, second, name)

 

posted @ 2022-06-12 18:58  hanyr  阅读(25)  评论(0)    收藏  举报