如何使用BeautifulSoup访问子页面(相同的url不同的内容)?

2024-05-16 12:02:52 发布

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

在Python上使用BeautifulSoup,我试图从这个页面的子页面中刮取一些内容

https://www.mmorpg-stat.eu/0_fiche_alliance.php?pays=5&ftr=500208.all&univers=_146

更准确地说,标题为enter image description here的子页面

问题是,通过点击这个按钮,url不会改变(这称为子页面吗?如果不是,那是什么?)所以我不能用

url = '...'
requests.get(url)

查看浏览器控制台,按钮代码是

<td width="250" align="center" valign="middle" class="Style1_f_j barre_joueur1 fond_56_1" style="cursor:pointer;text-transform: uppercase" onclick="fcache12('faCacher');fcache13('ffond_gris');document.form1_2date.statview.value='2';document.forms['form1_2date'].submit();return false;">
                 <span style="color:#ffffff;">&nbsp;&nbsp;Other information</span>
</td>

我所能理解的是,单击按钮时,会调用一些fcache方法

如何访问子页面


Tags: httpsurl内容stylewww页面document按钮
1条回答
网友
1楼 · 发布于 2024-05-16 12:02:52

All I can understand is that when clicked, the button calls some fcache method.

onclick="fcache12('faCacher');fcache13('ffond_gris');document.form1_2date.statview.value='2';document.forms['form1_2date'].submit();return false;"

它实际上调用了两个不同的方法:fcache12()fcache13()然后它在页面中找到一个表单并提交它

document.forms['form1_2date'].submit()

如果您搜索'form1_2date',您将发现:

<form name="form1_2date" method="post">

所以要模拟点击这个按钮,需要调用requests.post()而不是requests.get()。您还需要确定应该传入的表单值。这些由表单中的所有<input>标记确定

或者,您可以使用selenium或类似的库来模拟浏览器中的用户交互,而不是试图直接发出请求

相关问题 更多 >