2017-03-04 4 views

Antwort

0

Nun, diese Frage ist fehlerhaft, Websites, die Sie scrappen möchten, müssen zum Beispiel etwas gemeinsam haben.

from bs4 import BeautifulSoup 
from urllib import request 
import urllib.request 

for counter in range(0,10):   
    # site = input("Type the name of your website") Python 3+ 
    site = raw_input("Type the name of your website") 
    # Takes the website you typed and stores it in > site < variable 
    make_request_to_site = request.urlopen(site).read() 
    # Makes a request to the site that we stored in a var 
    soup = BeautifulSoup(make_request_to_site, "html.parser") 
    # We pass it through BeautifulSoup parser in this case html.parser 
    # Next we make a loop to find all links in the site that we stored 
    for link in soup.findAll('a'): 
     print link['href'] 
0

Wie bereits erwähnt, hat jede Seite ihre eigenen Einstellungen für Selektoren (,, usw.). Ein einzelner generischer Crawler ist nicht in der Lage, in eine URL zu gehen und intuitiv zu verstehen, was zu scrapen ist.

BeautifulSoup ist möglicherweise nicht die beste Wahl für diese Art von Anfrage. Scrapy ist eine andere Web-Crawler-Bibliothek, die etwas robuster ist als BS4.

ähnliche Frage hier auf Stackoverflow: Scrapy approach to scraping multiple URLs

Scrapy Dokumentation: https://doc.scrapy.org/en/latest/intro/tutorial.html