使用BeautifulSoup或LXML.HTML进行Web爬网

使用BeautifulSoup或LXML.HTML进行Web爬网,第1张

使用BeautifulSoup或LXML.HTML进行Web爬网

答案基于@hoju:

import lxml.htmlimport calendarfrom datetime import datetimeexDate  = "2014-11-22"symbol  = "LLY"dt      = datetime.strptime(exDate, '%Y-%m-%d')ym      = calendar.timegm(dt.utctimetuple())url     = 'http://finance.yahoo.com/q/op?s=%s&date=%s' % (symbol, ym,)doc     = lxml.html.parse(url)table   = doc.xpath('//table[@]/tbody/tr')rows    = []        for tr in table:     d = [td.text_content().strip().replace(',','') for td in tr.xpath('./td')]     rows.append(d)print rows


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5661676.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存