我试过this它列出了我网站上的所有网址。
from scrapy.selector import HtmlXPathSelector
from scrapy.spider import BaseSpider
from scrapy.http import Request
DOMAIN = 'example.com'
URL = 'http://%s' % DOMAIN
class MySpider(BaseSpider):
name = DOMAIN
allowed_domains = [DOMAIN]
start_urls = [
URL
]
def parse(self, response):
hxs = HtmlXPathSelector(response)
for url in hxs.select('//a/@href').extract():
if not ( url.startswith('http://') or url.startswith('https://') ):
url= URL + url
print url
yield Request(url, callback=self.parse)

我想列出有一些文字的网址,说" Scrappy Test"在网页上。任何帮助将不胜感激。
答案 0 :(得分:0)
如果您已经拥有所有网址(正如您在评论中所说),但想要通过子字符串过滤它们,请尝试:
if 'Scrapy Test' in url:
print url
yield Request(url)