【问题标题】:Python - Urllib2 Wait for page to load to scrape dataPython - Urllib2 等待页面加载以抓取数据
【发布时间】:2015-09-27 09:44:05
【问题描述】:

首先,我想说我不想使用 Python 2.7.10 未提供的任何库。相同的问题发布在 Stack Overflow 上,但在 Requests 库中得到了回答。

我有一个使用 urllib2 登录 Roblox.com 的脚本。要在我尝试登录之前检查是否有验证码,我想做check_captcha = re.findall('recaptcha_image', newlogin),但 roblox 需要重定向到验证码登录页面,并且验证码必须加载到页面上。

那么如何让 Python 等待完全重定向/加载页面,然后再继续 .read() 并抓取它。

【问题讨论】:

  • 你可以试试time.sleep(10) 可能有用

标签: python redirect web-scraping load captcha


【解决方案1】:

这将在读取之前等待 10 秒:

import urllib2
import time
url = 'Roblox url'
data = urllib2.urlopen(url)
time.sleep(10)
data = data.read()

【讨论】:

  • 谢谢,这行得通。我发现 Roblox 打印了We need to make sure you're not a robot! To sign in, please type the words in the picture.,所以我改为使用re.findall('robot', newlogin),而不是等待验证码加载。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-08
相关资源
最近更新 更多