python页面加载完_如何等待页面加载完成?

我尝试了下面的代码,但它总是在得到大小之前返回。在# config.url = 'http://www.neimanmarcus.com/Stuart-Weitzman-Reserve-Suede-Over-the-Knee-Boot-Black/prod179890262/p.prod'

import urllib2

import requests

import config

import time

from lxml.cssselect import CSSSelector

from lxml.html import fromstring

print config.url

headers = {

"Host": "www.neimanmarcus.com",

"Connection": "keep-alive",

"Content-Length": 106,

"Pragma": "no-cache",

"Cache-Control": "no-cache",

"Accept": "*/*",

"Origin": "http://www.neimanmarcus.com",

"X-Requested-With": "XMLHttpRequest",

"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36",

"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",

"Referer": "http://www.neimanmarcus.com/Stuart-Weitzman-Reserve-Suede-Over-the-Knee-Boot-Black/prod179890262/p.prod",

"Accept-Language": "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,fr;q=0.2,cs;q=0.2,zh-TW;q=0.2"

}

request = urllib2.Request(config.url, headers=headers)

html = urllib2.urlopen(request)

time.sleep(10)

html = html.read()

print html

html = fromstring(html)

sel = CSSSelector('option.addedOption')

try:

options = sel(html)

print options

except Exception as e:

print e

如何获得整个页面的信息(尤其是启动大小)?在

#coding:utf-8 import time import webbrowser as web import os import random #随机选择一个浏览器打开网页 def open_url_use_random_browser(): #定义要访问的地址 url='http://www.baidu.com' #定义浏览器路径 browser_paths=[r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe', #r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', #r'C:\Program Files (x86)\Opera\launcher.exe', #r'C:\Users\Administrator\AppData\Roaming\qianying\qianying.exe', #r'C:\Users\Administrator\AppData\Local\115Chrome\Application\115chrome.exe', #r'C:\Program Files (x86)\Internet Explorer\iexplore.exe', #r'D:\Program Files(x86)\SouExplorer\SogouExplorer\SogouExplorer.exe' ] #选择一个浏览器 def chose_a_browser_open_url(browser_path,url): #如果传入的浏览器位置不存在,使用默认的浏览器打开 if not browser_path: print ('using default browser to open') web.open_new_tab(url)#使用默认浏览器,就不再结束进程 else: #判断浏览器路径是否存在 if not os.path.exists(browser_path): print ('current browser path not exists,using default browser') #浏览器位置不存在就使用默认的浏览器打开 browser_path='' chose_a_browser_open_url(chose_a_browser_open_url,url) else: browser_task_name=browser_path.split('\\')[-1]#结束任务的名字 browser_name=browser_task_name.split('.')[0]#自定义的浏览器代号 print (browser_name) web.register(browser_name, None,web.BackgroundBrowser(browser_path)) web.get(browser_name).open_new_tab(url)#使用新注册的浏览器打开网页 print ('using %s browser open url successful' % browser_name) time.sleep(5)#等待打开浏览器 # kill_cmd='taskkill /f /IM '+browser_task_name#拼接结束浏览器进程的命令 # os.system(kill_cmd) #终结浏览器 browser_path=random.choice(browser_paths)#随机从浏览器中选择一个路径 chose_a_browser_open_url(browser_path,url) if __name__ == '__main__': print (''''' ***************************************** ** Welcome to python of browser ** ** Created on 2019-04-28 ** ** @author: Louise_ZOU ** ***************************************** ''') open_url_use_random_browser()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值