Python/羊皮屑响应。替换()方法无效?

2024-09-23 04:32:57 发布

您现在位置:Python中文网/ 问答频道 /正文

当试图改变响应.url与响应。替换在调用yield请求之前,我得到相同的结果?语法似乎是正确的。在

print(response.url)
response.replace(url='https://techcrunch.com/search/heartbleed#stq=heartbleed&stp=2')
print(response.url)  

next = self.driver.find_element(By.XPATH,"//a[@class='page-link next']")  
nextpage = next.get_attribute("href")  
yield scrapy.Request(url=nextpage, dont_filter=False)

注意:
1我分配了两次网址(obv.不需要,如果它会工作。。。grrr)
2.nextpage是与代码第2行完全相同的url

输出:

^{pr2}$

我有一种感觉,这就是为什么我不能去其他链接的原因,因为回应总是停留在同一个网站,而不是跟踪新的链接


Tags: httpscomurlsearch链接response语法replace
1条回答
网友
1楼 · 发布于 2024-09-23 04:32:57

我猜replace方法不会执行就地操作,但会返回结果:

replace([url, status, headers, body, request, flags, cls])
Returns a Response object with the same members, except for those members given new values by whichever keyword arguments are specified.

所以我会尝试一下:

^{pr2}$

相关问题 更多 >