擅长:python、mysql、java
<p>上次检查时,您不能通过单击带有BeautifulSoup和Python的按钮来提交表单。我经常看到两种典型的方法:</p>
<ol>
<li><strong>对表单进行反向工程</strong></li>
</ol>
<p>如果表单进行AJAX调用(例如,在后台发出请求,对于用React或Angular编写的spa来说很常见),那么最好的方法是使用Chrome或其他浏览器中的network requests选项卡来了解端点是什么以及负载是什么。一旦得到了这些答案,就可以使用<code>requests</code>库向使用<code>data=your_payload_dictionary</code>的端点发出POST请求(例如,手动执行表单在幕后执行的操作)。阅读<a href="https://www.codementor.io/codementorteam/how-to-scrape-an-ajax-website-using-python-qw8fuitvi" rel="nofollow noreferrer">this post</a>了解更详细的教程。在</p>
<ol start=“2”>
<li><strong>使用无头浏览器</strong></li>
</ol>
<p>如果网站上写的是ASP.NET或者类似的MVC框架,那么最好的方法是使用headless浏览器填写表单并单击submit。一个流行的框架是<a href="https://selenium-python.readthedocs.io/getting-started.html" rel="nofollow noreferrer">Selenium</a>。这将模拟普通浏览器。阅读<a href="http://toddhayton.com/2015/05/14/using-selenium-to-scrape-aspnet-pages-with-ajax-pagination/" rel="nofollow noreferrer">this post</a>以获得更详细的教程。在</p>
<p>粗略地看一下你正在处理的页面,我推荐第二种方法。在</p>