【发布时间】:2018-03-16 14:32:55
【问题描述】:
我想从这个搜索结果页面获取每篇文章的所有链接: https://www.ncbi.nlm.nih.gov/gds/?term=lung+cancer
但我无法获取下一页的网址。来自<div class="pagination">,它说:
<a name="EntrezSystem2.PEntrez.Gds.Gds_ResultsPanel.Entrez_Pager.Page" title="Next page of results" class="active page_link next" href="#" sid="3" page="2" accesskey="k" id="EntrezSystem2.PEntrez.Gds.Gds_ResultsPanel.Entrez_Pager.Page">Next ></a>
因此我使用 python urllib 来检索下一页的 url,以便使用 BeautifulSoup 获取其内容:
param2=urllib.urlencode({'sid':3,'page':2,'accesskey':'k','id':'EntrezSystem2.PEntrez.Gds.Gds_ResultsPanel.Entrez_Pager.Page'})
f2=urllib.urlopen('https://www.ncbi.nlm.nih.gov/gds/?term=lung+cancer',param2)
soup2 = BeautifulSoup(f2.read(), 'html.parser')
现在的问题是,即使我将页码从 1 更改为 10,我总是得到第 1 页的内容。谁能告诉我我做错了什么?
【问题讨论】:
标签: php python pagination beautifulsoup scrapy