我正试图从这个网页上获取信息:https://www.tmea.org/programs/all-state/history
我想从第一个下拉菜单中选择几个选项,并使用Beautiful Soup来拉取我需要的信息。首先,我试着用靓汤提取不同的选择:
import requests
from bs4 import BeautifulSoup
page = requests.get('https://www.tmea.org/programs/all-state/history')
soup = BeautifulSoup(page.text, 'html.parser')
body = soup.find(id = 'organization')
options = body.find_all('option')
for name in options:
child = name.contents[0]
print(child)
这对于拉取不同的选项很有效,但是我希望能够提交一个特定的选项并获取该信息。我试着补充:
^{pr2}$我以前在其他使用POST的页面中使用过这个,我不太明白为什么这个例子不同。使用下拉选项是否意味着我必须使用诸如Selenium之类的东西?我以前用过,但我不知道怎么和靓汤一起用。在
1)我没有看到在XHR和Fetch中使用POST(见下面的编辑)
2)是的,你可以用硒来做这个。像平常一样用硒来做桌子。一旦表被渲染,你就可以把它输入BeautifulSoup。例如:
老实说,我不会为此费心使用beauthoulsoup,因为它看起来像是一个
^{pr2}$<table>
标记。让熊猫来做这个工作:编辑
我在Doc下找到了POST请求方法。您需要在有效负载中包含更多参数:
输出:
相关问题 更多 >
编程相关推荐