使用 Beautifulsoup 和请求抓取 'N' 页(如何获取真实页码)

Scraping 'N' pages with Beautifulsoup and Requests (How to obtain the true page number)

我想获取网站中所有的标题()。

http://www.shyan.gov.cn/zwhd/web/webindex.action

现在,我的代码只成功抓取了一页。但是,在上面的站点上有多个可用的页面,我想从中抓取。

例如上面的url,当我点击link到"page 2"时,整体url并没有改变。我查看了页面源代码,看到 javascript 代码可以像这样前进到下一页:javascript:gotopage(2) 或 javascript:void(0)。 我的代码在这里(获取第 1 页)

from bs4 import Beautifulsoup
import requests
url = 'http://www.shyan.gov.cn/zwhd/web/webindex.action'
r =  requests.get(url)
soup = Beautifulsoup(r.content,'lxml')
titles = soup.select('td.tit3 > a')
for title in titles:
    print(title.get_text())

如何更改我的代码以从所有可用的列出页面中抓取标题? 非常感谢!

尝试使用以下URL格式:

http://www.shiyan.gov.cn/zwhd/web/webindex.action?keyWord=&searchType=3&page.currentpage=2&page.pagesize=15&page.pagecount=2357&docStatus=&sendOrg=

站点正在使用 javascript 将隐藏页面信息传递给服务器以请求下一页。当您查看源代码时,您会发现:

<form action="/zwhd/web/webindex.action" id="searchForm" name="searchForm" method="post">
 <div class="item">
     <div class="titlel">
      <span>留言查询</span>
     <label class="dow"></label>
     </div>
     <input type="text" name="keyWord" id="keyword" value="" class="text"/>
     <div class="key">
        <ul>
            <li><span><input type="radio" checked="checked" value="3" name="searchType"/></span><p>编号</p></li>
            <li><span><input type="radio" value="2" name="searchType"/></span><p>关键字</p></li>
        </ul>    
     </div>
     <input type="button" class="btn1" onclick="search();" value="查询"/>
  </div>
  <input type="hidden" id="pageIndex" name="page.currentpage" value="2"/>
  <input type="hidden" id="pageSize" name="page.pagesize" value="15"/>
  <input type="hidden" id="pageCount" name="page.pagecount" value="2357"/>
  <input type="hidden" id="docStatus" name="docStatus" value=""/>
  <input type="hidden" id="sendorg" name="sendOrg" value=""/>
  </form>