2017-03-04 22 views

回答

0

那么这个问题是有缺陷的,你想刮的网站必须有一些共同点。

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']