- 有时我们获取的url地址是不完整的,需要拼接一个完整的url。
- 方法一: 使用+号拼接
url = “localhost” + response.css("#.pp a::attr(src)").extract_first(default=None)
- 方法二 使用 join
url = "".join([host,response.xpath("//a[@class='pic']/img/@href").extract_first(default=None)])
- 方法三 使用reponse.joinurl
url = response.urljoin(response.css(.pic a::attr(href)).extract_first())
- 方法四 使用response.follow直接请求
yield response.follow(next_url,callback=self.parse)