Selenium Webdriver无法打开正确的URL,而是会打开空白页面

时间:2020-08-13 00:40:57

标签: python selenium selenium-webdriver scrape

我正在使用Selenium Webdriver尝试从realestate.com.au抓取信息,这是我的代码:

从selenium.webdriver导入Chrome 从bs4导入BeautifulSoup

path = 'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe'
url = 'https://www.realestate.com.au/buy'
url2 = 'https://www.realestate.com.au/property-house-nsw-castle+hill-134181706'
webdriver = Chrome(path)
webdriver.get(url)
soup = BeautifulSoup(webdriver.page_source, 'html.parser')
print(soup)

它可以很好地使用URL,但是当我尝试执行同样的操作来打开url2时,它会打开一个空白页面,并且我检查了控制台,得到了以下内容: “无法加载资源:服务器响应状态为429() 关于:空白:1无法加载资源:net :: ERR_UNKNOWN_URL_SCHEME 149e9513-01fa-4fb0-aad4-566afd725d1b / 2d206a39-8ed7-437e-a3be-862e0f06eea3 / fingerprint:1无法加载资源:服务器的响应状态为404()“

在打开URL时,我尝试搜索任何内容,这也导致了url2之类的空白页面。

2 个答案:

答案 0 :(得分:0)

我认为您应该尝试在获取行之前添加driver.implicitly_wait(10),因为这会添加隐式等待,以防页面加载太慢而导致驱动程序无法访问该站点。另外,您应该考虑试用Firefox Webdriver,因为此错误似乎只影响Chrome浏览器。

答案 1 :(得分:0)

www.realestate.com.au网站似乎正在使用Akamai安全工具。

DNS快速查找显示www.realestate.com.au解析为dualstack.realestate.com.au.edgekey.net。

他们最有可能使用Bot Manager产品(https://www.akamai.com/us/en/products/security/bot-manager.jsp)。我最近在另一个网站上遇到了这个问题。

通常轮换用户代理和IP地址(最好使用住宅 代理)应该可以解决问题。您希望每次使用“新”浏览器配置文件加载网站。您还应该签出https://github.com/67-6f-64/akamai-sensor-data-bypass