从SPAN ID beatifulsoup正确获取数据

时间:2019-04-14 03:19:26

标签: python

我需要带出该页面的特定值,但不会带给我。

这是我的代码:

import urllib.request
from bs4 import BeautifulSoup`

url="http://www.mae.com.ar/old.aspx?p=mercados/Forex/Default.aspx"
page = urllib.request.urlopen(url)
soup = BeautifulSoup(page.read(), "html.parser")
target = soup.find("span", id="ctl00_ContentPlaceHolder1_GVPREREFBCRA_ctl02_Label20")
print (target)

1 个答案:

答案 0 :(得分:0)

按如下所示更改URL:

import requests
from bs4 import BeautifulSoup as bs

r = requests.get('http://www.mae.com.ar/mercados/Forex/Default.aspx')
soup = bs(r.content, 'lxml')
quote = soup.select_one('#ctl00_ContentPlaceHolder1_GVPREREFBCRA_ctl02_Label20').text