擅长:python、mysql、java
<p>下面的代码将打印出页面上的所有href:</p>
<pre><code>import scrapy
class stackoverflow20170129Spider(scrapy.Spider):
name = "stackoverflow20170129"
allowed_domains = ["masterdatascience.es"]
start_urls = ["http://www.masterdatascience.es/",]
def parse(self, response):
for href in response.xpath('//a/@href'):
url = response.urljoin(href.extract())
print url
# yield scrapy.Request(url, callback=self.parse_dir_contents)
</code></pre>
<p>还有一件事:值得把www.从“允许的域名”中删除——如果你深入网站并开始访问诸如anewpage.masterdatascience.es那么包括www.会阻止这个页面</p>