【问题标题】:How to get the link to all the pages of a website for data scraping [duplicate]如何获取指向网站所有页面的链接以进行数据抓取[重复]
【发布时间】:2016-04-28 23:57:06
【问题描述】:

我一直在开发一个程序,该程序使用 PHP 中的正则表达式从网站的特定页面抓取数据。

     <?php 
     ini_set("user_agent", "PHP");
     $url = "http://www.example.com/page.html";
     $output = file_get_contents($url);
     preg_match('#<h1 class="title" itemprop="name">(.*)</h1>#', $output, $match);
     echo $match[1] ."<br>";
     ?>

如何制作一个程序来获取网站的所有现有链接以从中抓取数据?而不是在浏览器中打开每个链接并手动插入,这比手动输入数据而不是抓取数据更糟糕。

我了解 JavaScript、Python 和 PHP,并且可以使用这三种语言中的任何一种。

【问题讨论】:

  • 是时候使用DOMDocument
  • @RodrigoDuterte 请解释一下怎么做

标签: javascript php


【解决方案1】:
import bs4
for link in bs4.BeautifulSoup(urllib2.urlopen(target_url).read()).find_all("a"):
    print link

【讨论】:

    猜你喜欢
    • 2020-04-25
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    相关资源
    最近更新 更多