【问题标题】:How to get scrape information from a textbook buyback website?如何从教科书回购网站获取抓取信息?
【发布时间】:2017-02-05 02:59:47
【问题描述】:

我正在制作一个程序,其中一个部分是找出教科书的最佳回购价格。我正在尝试从“https://bookscouter.com”中抓取值,例如“https://bookscouter.com/prices.php?isbn=1285428226&searchbutton=Sell”的值是 34$。问题是该网站绝对不是静态的,简单的 python 抓取并不能真正起作用。我该怎么办?某种要求?我对网络工作不是很有经验,所以任何建议都将不胜感激。最好的,

【问题讨论】:

标签: php python html request screen-scraping


【解决方案1】:

此页面使用 Ajax 来获取一些附加信息。 https://bookscouter.com/prices.php?isbn=1285428226&searchbutton=Sell的源码显示

<script language="javascript" type="text/javascript">
    function fetchresults_cb(search_id, text) {
        replaceContent('price_results', text);
        if(text.match(/INCOMPLETE/i)) {
            currentTime = new Date();
            time = currentTime.getTime();
            delayfunc = "AjaxRetrieve('/ajax_prices.php?type=PREFERRED&isbn=1285428226&search_id="+search_id+"&ts="+time+"', 'fetchresults_cb(\\'"+search_id+"\\', THISREQ.responseText)', 'true');";
            setTimeout(delayfunc, 3000);
        }

</script>

解析这种页面有不同的方法。

第一种方法是在 Python 中重新实现上面的源代码并获取额外的资源,就像浏览器在 JavaScript 执行期间所做的那样。您可以分析页面的完整源代码或使用network monitor 来识别所需信息可用的 URL 地址。

第二种方法是使用 Selenium,它使用浏览器引擎执行 JavaScript 并提供包含所有必需信息的完整源代码。

我相信您拥有 bookscouter.com 的数据库所有者的权限来执行此类活动。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多