Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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
Java 从数百万个URL中删除标题和元标记_Java_Python_Web_Web Scraping_Web Crawler - Fatal编程技术网

Java 从数百万个URL中删除标题和元标记

Java 从数百万个URL中删除标题和元标记,java,python,web,web-scraping,web-crawler,Java,Python,Web,Web Scraping,Web Crawler,到目前为止,我已经看到了很多工具,如Scrapy或Selenium。基本上,问题不在于如何抓取一个网站,而是如何在尊重robots.txt和互联网礼貌的同时,在相当长的时间内抓取数百万个网站 到目前为止,我已经收集了超过10亿个URL,但现在我需要刮取每个URL,以便获取标题和元标记 这可能吗?怎么做?哪种工具可以让我在不被网站阻止或禁止的情况下抓取几个URL 谢谢所以我在这里提供了一个全面的解决方案。使用和libs将是您的最佳解决方案 首先,我假设你有10亿个URL。您的目标是从这些站点获取标

到目前为止,我已经看到了很多工具,如Scrapy或Selenium。基本上,问题不在于如何抓取一个网站,而是如何在尊重robots.txt和互联网礼貌的同时,在相当长的时间内抓取数百万个网站

到目前为止,我已经收集了超过10亿个URL,但现在我需要刮取每个URL,以便获取标题和元标记

这可能吗?怎么做?哪种工具可以让我在不被网站阻止或禁止的情况下抓取几个URL


谢谢

所以我在这里提供了一个全面的解决方案。使用和libs将是您的最佳解决方案

首先,我假设你有10亿个URL。您的目标是从这些站点获取标题和元内容

import requests
from bs4 import BeautifulSoup

urls = ['http://github.com', 'http://bitbucket.com', ...] # upto 1 billion urls :o
# looping through the billion URLs 
for url in urls:
    req = requests.get(url).text # making the request
    soup = BeautifulSoup(req, 'html5lib') 
    meta_content = soup.findAll('meta', content=True) # here you get your meta tag contents
    title_content = soup.findAll('title') # here you get your title tag contents
    print ("Meta for %s: %s" % (url, meta_content))
    print ("Title for %s: %s" % (url, title_content))

注意:html.parser不能正确解析标记。它没有意识到它们是自动关闭的,因此我使用了html5lib库。

。我的意思是更多的工具作为代码片段。因为一个正常的迭代会让我被任何网站屏蔽。很抱歉