【问题标题】:Scraping startpage with bs4 and requests使用 bs4 和请求抓取起始页
【发布时间】:2017-12-09 20:47:31
【问题描述】:

我正在尝试从http://startpage.com/ 中抓取搜索结果,我已经使用 bs4 和请求将结果全部准备好了。在能够抓取结果后,我遇到了问题。我无法进入搜索结果的下一页。我找不到使用网页浏览开发者工具的链接。当我检查元素时,这就是它显示的内容<a href="javascript:;" class="numbers_st" onclick="mysubmit(10); return false;" id="2">2</a> 那是数字 2 按钮。另一个选项是下一个按钮<a href="javascript:document.nextform.submit();" class="numbers_st" style="width:200px; text-align:left;">Next<span class="i_next"></span></a> 我如何提出请求,或者在抓取第一页的结果后我需要做什么才能进入下一页。

import requests
from bs4 import BeautifulSoup
def dork():
    url = 'https://www.startpage.com/do/search?cmd=process_search&query=inurl:admin&language=english_au&cat=web&with_language=&with_region=&pl=&ff=&rl=&abp=-1&with_date=m'
    source_code = requests.get(url, 'html')
    plain_txt = source_code.text
    soup = BeautifulSoup(plain_txt, "lxml")
    for text in soup.find_all('h3', {'class': 'clk'}):
        for link in text.find_all('a'):
            href = link.get('href')
            print(href)
dork()

这就是获取链接的代码。

【问题讨论】:

    标签: web-scraping request search-engine python-3.5


    【解决方案1】:

    我会推荐你​​尝试 Selenium/PhantomJS,它让你能够拥有一个真正的、无头的和可编写脚本的浏览器。结帐this answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      相关资源
      最近更新 更多