我正在尝试爬网此特定网页: https://www.grainger.com/category/abrasives/abrasive-blasting/abrasive-blasting-cabinets
使用以下代码行:
page = requests.get("https://www.grainger.com/category/abrasives/abrasive-blasting/abrasive-blasting-cabinets")
但是,该页面带有默认的“表”视图。但是我要爬网的网页是启用了“列表视图”时。如何请求启用了“列表”视图的网页,如下图所示:
答案 0 :(得分:1)
从Google Chrome浏览器的“网络”标签中查看,似乎我的网站通过设置cookie来了解显示哪个视图,因此,如果要以列表形式查看,可以在请求中设置该cookie。
//now check for the AJAX change to this element...normally takes about 1 second
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='balance-sms' and contains(text(),'" +newBalence +"')]")));
//continue...
将来,您可以检查this reference来帮助您了解浏览时的实际情况。