如何使用python从表中提取数据?

时间:2019-05-20 05:54:55

标签: python-3.x

我正在尝试从此网站“ https://www.qualitydiamonds.co.uk/one-carat-loose-diamonds/#”中显示的表格中获取数据。

我尝试了下面的代码,但是我只能从网页上显示的4个主要菱形中获取数据,而从实际表中没有任何数据。

import requests
from bs4 import BeautifulSoup

url = "https://www.qualitydiamonds.co.uk/one-carat-loose-diamonds/"


response = requests.get(url)
print(response)

soup = BeautifulSoup(response.text, 'html.parser')

one_a_tag = soup.findAll('span', class_='price')

print(one_a_tag)

1 个答案:

答案 0 :(得分:0)

嘿,您可以在下面尝试以下代码:

import requests
import bs4 as bs

url = "https://www.qualitydiamonds.co.uk/one-carat-loose-diamonds/"

response = requests.get(url)

soup = bs.BeautifulSoup(response.text, 'lxml')

price = soup.find(class_='price')
print(price.text)