我已经发现并阅读了不少关于刮削的文章,但作为一个初学者,我不知怎么的不知所措。 我想从表(https://www.senamhi.gob.pe/mapas/mapa-estaciones/_dat_esta_tipo.php?estaciones=472CA750)中获取数据
我试用了beautifulsoup,可以得到可用选项标签的列表(请参阅soup对象中的选项)
我现在很难获得实际内容/如何访问表中的每个日期/选项,并将其保存到一个文件夹中
有什么建议吗
下面是获取选项的代码:
from bs4 import BeautifulSoup
import requests
resp = requests.get("https://www.senamhi.gob.pe/mapas/mapa-estaciones/_dat_esta_tipo.php?estaciones=472CA750")
html = resp.content
soup = BeautifulSoup(html)
option_tags = soup.find_all("option")
当我查看您给定的url时,我认为该表嵌入了给定的网站:
当您单击srchttps://www.senamhi.gob.pe/mapas/mapa-estaciones/_dat_esta_tipo.php?estaciones=472CA750时,页面将打开并显示相同的表,以便您可以使用soap访问此页面。我给你试试看,结果是真的
**所有代码:**
输出:
以上代码只获取日期。如果要访问给定日期的所有元素,可以创建一个数组并附加它。只是会改变下面的代码
相关问题 更多 >
编程相关推荐