Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 解析网页时调用onclick方法_Javascript_Python_Beautifulsoup_Urllib2 - Fatal编程技术网

Javascript 解析网页时调用onclick方法

Javascript 解析网页时调用onclick方法,javascript,python,beautifulsoup,urllib2,Javascript,Python,Beautifulsoup,Urllib2,免责声明:这是我第一次尝试网络抓取。如果这是一个非常简单的问题,请不要介意 我从一个网站上获取html源代码,如下所示 def get_soup(site): """get the html source for a web site""" try: logging.debug("Getting data from:" + site) req = urllib2.Request(site) req.add_header('Accept', '*/*') req.a

免责声明:这是我第一次尝试网络抓取。如果这是一个非常简单的问题,请不要介意

我从一个网站上获取html源代码,如下所示

def get_soup(site):
"""get the html source for a web site"""
try:
    logging.debug("Getting data from:" + site)
    req = urllib2.Request(site)
    req.add_header('Accept', '*/*')
    req.add_header('User-Agent', 'web-scraping')
    page = urllib2.urlopen(req).read()        
    return BeautifulSoup(page)       
except:
    logging.debug("Check the site: " + str(site))
    raise   
汤有一个如下的onclick方法。在发出url请求时(最好)或之后(如果可能的话),是否有方法调用此方法

soup=get_soup(opt_site.replace(“,symbol).replace(“,expiry.strftime(“%d%b%Y”))
现货价格=汤.findAll('table')[0]。findChildren('td')[1]。findChildren('span')[0]
截至2013年12月23日15:30:25 IST

BeautifulSoup不处理javascript。您应该使用能够处理javascript的东西;例如

soup = get_soup(opt_site.replace("<symbol>", symbol).replace("<expiry>", expiry.strftime("%d%b%Y")))
spot_price = soup.findAll('table')[0].findChildren('td')[1].findChildren('span')[0]

<span>As on Dec 23, 2013 15:30:25 IST<a> <img src="/live_market/resources/images/refressbtn.gif" onclick="refresh();" style="cursor: pointer" title="refresh" /></a></span>