无法浏览下拉列表项[Python][beautifulsoup]

2024-05-05 05:14:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉网络垃圾,我正在刮一个网站-https://www.valueresearchonline.com/funds/22/uti-mastershare-fund-regular-plan/

在这篇文章中,我想删掉这篇课文-常规计划 enter image description here

但问题是,当我使用inspect元素时, 代码-

import requests
from bs4 import BeautifulSoup
import csv
import sys

url = 'https://www.valueresearchonline.com/funds/newsnapshot.asp?schemecode=22'
res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")
regular_direct = soup.find('span',class_="filter-option pull-left").text

print(regular_direct)

我在打印中没有得到任何结果,我不知道为什么,inspect元素和view page source中的代码也不同,因为在view page source中,这个跨度和类不存在。 为什么我一个也得不到??有谁能告诉我,我怎样才能得到那个文本,为什么检查元素代码和查看页面源代码是不同的


Tags: 代码httpsimportcomurl元素wwwres
1条回答
网友
1楼 · 发布于 2024-05-05 05:14:45

您需要更改选择器,因为下载的html源不同

import requests
from bs4 import BeautifulSoup
import csv
import sys

url = 'https://www.valueresearchonline.com/funds/newsnapshot.asp?schemecode=22'
res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")
regular_direct = soup.find("select", {"id":"select-plan"}).find("option",{"selected":"selected"}).get_text(strip=True)

print(regular_direct)

输出:

Regular plan

相关问题 更多 >