我正在尝试lmxl使用Python 3.4在我的Windows 8.1笔记本电脑上安装并且惨遭失败.
首先,我尝试了简单明了的解决方案:pip install lxml.但是,这不起作用.这是它说的:
Downloading/unpacking lxml
Running setup.py (path:C:\Users\CARTE_~1\AppData\Local\Temp\pip_build_carte_000\lxml\setup.py) egg_info for package lxml
Building lxml version 3.4.2.
Building without Cython.
ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
warning: no previously-included files found matching '*.py'
Installing collected packages: lxml
Running setup.py install …Run Code Online (Sandbox Code Playgroud) 我正试图从雅虎获取股票数据!财务使用Python 2.7.9,但我只需要本月第3个星期五的数据.我有一个获取数据的功能,但需要一种方法来获取日期.我想要这样的东西:
def get_third_fris(how_many):
# code and stuff
return list_of_fris
Run Code Online (Sandbox Code Playgroud)
因此,该呼叫get_third_fris(6)将在当前日期之后返回6个项目长的第3个星期五列表.日期需要是Unix时间戳.
(我有几乎没有经验time或者datetime,请解释一下你的代码做什么.)
谢谢!
我一直在寻找以不同方式映射退格键的方法,但这不是我所追求的.
我正在编写一个python代码的程序,基本上我想写一行代码,导致程序认为有人只是点击了GUI中的Backspace键(因为退格键删除了一些东西)
我如何在退格键击中编码?
我正在编写一个 Python 程序来从雅虎财经获取股票数据。我希望它能够在多个日期从多个股票获取数据。URL 是这样的:https://finance.yahoo.com/q/op?s=GOOG&date=1423785600,我知道如何更改股票符号,但是日期的格式如何?有没有办法计算这个,或者我应该暴力破解它并查看下拉日期菜单上的所有选项?
我正在编写一个程序,使用该xlsxwriter模块将数据写入Excel文件.
打开工作簿的代码是:
excel = xlsxwriter.Workbook('stock.xlsx')
Run Code Online (Sandbox Code Playgroud)
这曾经工作过.然后我在程序的底部更改了一些东西(在该行之后waaaaay),现在它不起作用,这样说:
Exception ignored in: <bound method Workbook.__del__ of <xlsxwriter.workbook.Workbook object at 0x02C702B0>>
Traceback (most recent call last):
File "c:\python34\lib\site-packages\xlsxwriter\workbook.py", line 147, in __del__
raise Exception("Exception caught in workbook destructor. "
Exception: Exception caught in workbook destructor. Explicit close() may be required for workbook.
Run Code Online (Sandbox Code Playgroud)
这种情况发生在我再次运行它之前忘记关闭文件时(因为它试图写入在Excel中打开但无法正常工作的文件),但我甚至没有打开Excel,它就是这样做的.
我怎样才能解决这个问题?我需要重启还是什么?
此外,try...except如果初始化不起作用,我试图有一个循环来停止程序.即使except:只有,没有特定的例外,它仍然完成程序,除非我手动杀死它.该脚本基本上打开Excel文件,花费很长时间从Internet下载数据,然后将其写入Excel文件.如果初始化不起作用,我希望它停止,所以我不必等待脚本完成(最多可能需要15分钟).我很确定它与它说" Exception ignored" 的事实有关,但我不熟悉Python中的所有错误.
编辑:
我excel.close()在最后添加了一个命令,现在它没有给我第一个错误,但是第二个错误(更大更可怕):
Traceback (most recent call last):
File "C:\Users\carte_000\Python\stock_get_rev8.py", line 161, in <module>
excel.close()
File "c:\python34\lib\site-packages\xlsxwriter\workbook.py", line …Run Code Online (Sandbox Code Playgroud) python error-handling exception-handling exception xlsxwriter
我正试图获得股票的公司名称,行业和行业.我下载的HTML 'https://finance.yahoo.com/q/in?s={}+Industry'.format(sign),然后尝试用解析它.xpath()从lxml.html.
要获取我正在尝试抓取的数据的XPath,我会转到Chrome中的网站,右键单击该项目,单击Inspect Element,右键单击突出显示的区域,然后单击Copy XPath.这在过去一直对我有用.
可以使用以下代码重现此问题(我使用Apple作为示例):
import requests
from lxml import html
page_p = 'https://finance.yahoo.com/q/in?s=AAPL+Industry'
name_p = '//*[@id="yfi_rt_quote_summary"]/div[1]/div/h2/text()'
sect_p = '//*[@id="yfncsumtab"]/tbody/tr[2]/td[1]/table[2]/tbody/tr/td/table/tbody/tr[1]/td/a/text()'
indu_p = '//*[@id="yfncsumtab"]/tbody/tr[2]/td[1]/table[2]/tbody/tr/td/table/tbody/tr[2]/td/a/text()'
page = requests.get(page_p)
tree = html.fromstring(page.text)
name = tree.xpath(name_p)
sect = tree.xpath(sect_p)
indu = tree.xpath(indu_p)
print('Name: {}\nSector: {}\nIndustry: {}'.format(name, sect, indu))
Run Code Online (Sandbox Code Playgroud)
这给出了这个输出:
Name: ['Apple Inc. (AAPL)']
Sector: []
Industry: []
Run Code Online (Sandbox Code Playgroud)
它没有遇到任何下载困难,因为它能够检索name,但其他两个不起作用.如果我分别用tr[1]/td/a/text()和替换它们的路径tr[1]/td/a/text(),它会返回:
Name: ['Apple Inc. (AAPL)']
Sector: ['Consumer Goods', 'Industry Summary', 'Company …Run Code Online (Sandbox Code Playgroud) python ×5
date ×2
lxml ×2
atom-editor ×1
backspace ×1
exception ×1
html ×1
keystroke ×1
pip ×1
python-2.7 ×1
python-3.x ×1
typescript ×1
windows ×1
xlsxwriter ×1
xpath ×1