Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 网页抓取到HTML代码_Python_Ruby_Web Scraping - Fatal编程技术网

Python 网页抓取到HTML代码

Python 网页抓取到HTML代码,python,ruby,web-scraping,Python,Ruby,Web Scraping,我读过关于使用PERL、Ruby、Python和PHP来抓取或解析RSS提要的文章 如果我使用这些语言中的一种来刮取页面,是否可以将刮取的信息写入像index.HTML这样的HTML文件?我想从RSS提要中获取链接,并在我的主页上用它们制作菜单 每次我刮,我都要重写整个HTML文件?我有一个部分,标题,我需要每隔一个小时左右更改一次,它从被刮下的页面中获取信息 下面是每次运行scrape时需要更改的代码: <article class="grid_4"> <di

我读过关于使用PERL、Ruby、Python和PHP来抓取或解析RSS提要的文章

如果我使用这些语言中的一种来刮取页面,是否可以将刮取的信息写入像index.HTML这样的HTML文件?我想从RSS提要中获取链接,并在我的主页上用它们制作菜单

每次我刮,我都要重写整个HTML文件?我有一个部分,标题,我需要每隔一个小时左右更改一次,它从被刮下的页面中获取信息

下面是每次运行scrape时需要更改的代码:

<article class="grid_4">
        <div class="box-1">
          <h3>HEADLINES</h3>
          <ul class="list-1 p2">
            <li><a href="more.html"><b></b><strong>Lorem ipsum</strong> dolor amet, consectetuer</a></li>
            <li><a href="more.html"><b></b><strong>Adipiscing elit</strong> sed diam nonummy nibh</a></li>
            <li><a href="more.html"><b></b><strong>Euismod tincidunt</strong> laoreet dolore magna</a></li>
            <li><a href="more.html"><b></b><strong>Aliquam erat</strong> volutpat wisi enim ad minim</a></li>
            <li><a href="more.html"><b></b><strong>Veniam nostrud</strong> exerci tation ullamcorper</a></li>
            <li><a href="more.html"><b></b><strong>Suscipit lobortis</strong> nisl ut aliquip commodo</a></li>
            <li><a href="more.html"><b></b><strong>Duis autem</strong> vel eum iriure dolor hendrerit</a></li>
            <li><a href="more.html"><b></b><strong>In vulputate</strong> velit esse molestie consequat</a></li>
            <li><a href="more.html"><b></b><strong>Vel illum</strong> dolore eu feugiat nulla facilisis</a></li>
            <li><a href="more.html"><b></b><strong>At vero</strong> eros et accumsan</a></li>
          </ul>
          <div class="alignright p3"><a href="more.html" class="link-1">read more</a></div>
        </div>
        <a href="more.html" class="banner-1"></a> </article>
    </div>
有可能这样做吗?如果没有,你能告诉我从哪里开始阅读/学习它吗

是的,有可能:


装上漂亮的汤

pip install beautifulsoup4
然后

如果没有pip,请从此处安装:

美丽的汤会给你一个干净的网页版本。你可以在这个结构中搜索链接或任何你想要的信息

soup.find_all('a')
将为您提供页面中的所有链接

要将这些信息发布到网页上,有无限多的可能性,有些人会想到:

您可以生成网页

您可以生成一个网页并将其加载到iframe中

您可以生成一个JSON格式的文本文件,其中包含所有链接,并从嵌入在静态网页上的Javascript获取该文件

正如你所说,你可以运行Django

什么是最好的取决于很多因素——你多久刮一次?你应该多久刮一次?是否必须在web服务器上进行刮取,还是应该在定期上载到web服务器的其他计算机上进行刮取


模糊的问题,模糊的答案…

你可以抓取/解析任何东西:web请求就是web请求,响应就是响应。在网上搜索你想要的任何一种语言的刮削教程。@esaelPsnoroMoN-我不是问用什么来解析,我已经知道了,而且我知道它已经被问了10000次了。我想问的是,一旦你有了你想要的数据,我怎么把它放到实际的HTML页面上。我知道如何在Python中使用BeautifulSoup。我在问,一旦我有了我想要的数据,我怎么把它放到我的HTML页面上。我需要使用DJango或其他模板软件吗?