beauthulsoup在使用POST-form操作解析html时出现问题

2024-06-26 03:48:38 发布

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

通过此链接使用urllib2登录: Login to website using urllib2 - Python 2.7

我要做的是创建一个存储空间的虚拟映射,要做到这一点,我需要登录到基于web的管理服务器。因此使用了BS4和urllib。在

大多数请求都能正常工作,除了通过手动登录(通过网站)加载页面时的HTML与使用urllib时有明显的区别。在

以下是我使用urllib登录方式时的外观片段:

<div id="gridContainer" class='grid_12'></div>

<form action="/Inventory/UnpendStorageSpaces" method="post"><input name="__RequestVerificationToken" type="hidden" value=">>>>>>BLOCKED VALUE>>>>=" /><input id="deviceKey" name="deviceKey" type="hidden" value="" /><input id="facilityItemKey" name="facilityItemKey" type="hidden" value="" />

以下是我手动登录(通过网站)时的外观片段:

^{pr2}$

正如你所知道的,两者之间有明显的区别,只是想看看最好的解决办法是什么?在


Tags: namedividinputvalue网站type手动
1条回答
网友
1楼 · 发布于 2024-06-26 03:48:38

您得到的结果不同,因为该站点使用javascript和JQuery呈现页面,这在通过urllib获取页面时不会发生。在

查看the first answer到“使用Python进行Web抓取JavaScript页面”以获得Python内的解决方案。其他选择包括使用Selenium或Phantomjs,但希望您不必这样做。在

相关问题 更多 >