我在一个网页上运行查询,然后我得到结果网址.如果我右键单击查看html源代码,我可以看到JS生成的html代码.如果我只是使用urllib,python就无法获取JS代码.所以我看到了一些使用硒的解决方案.这是我的代码:
from selenium import webdriver
url = 'http://www.archives.com/member/Default.aspx?_act=VitalSearchResult&lastName=Smith&state=UT&country=US&deathYear=2004&deathYearSpan=10&location=UT&activityID=9b79d578-b2a7-4665-9021-b104999cf031&RecordType=2'
driver = webdriver.PhantomJS(executable_path='C:\python27\scripts\phantomjs.exe')
driver.get(url)
print driver.page_source
>>> <html><head></head><body></body></html>         Obviously It's not right!!
这是我在右键单击窗口中需要的源代码,(我想要信息部分)
</script></div><div class="searchColRight"><div id="topActions" class="clearfix 
noPrint"><div id="breadcrumbs" class="left"><a title="Results Summary"
href="Default.aspx?    _act=VitalSearchR ...... <<INFORMATION I NEED>> ... 
to view the entire record.</p></div><script xmlns:msxsl="urn:schemas-microsoft-com:xslt">
        jQuery(document).ready(function() {
            jQuery(".ancestry-information-tooltip").actooltip({
href: "#AncestryInformationTooltip", orientation: "bottomleft"});
        });
===========所以我的问题是===============如何获取JS生成的信息?
这是一个简单的测试
import numpy as np
data = np.array([-1,0,1])
print data.std()
>> 0.816496580928
我不明白这个结果是如何产生的?明显:
( (1^0.5 + 1^0.5 + 0^0.5)/(3-1) )^0.5 = 1
在matlab它给了我std([-1,0,1]) = 1.你能帮助我理解它是如何numpy.std()工作的吗?
我认为这是以前最流行的方式:
https://pytools.codeplex.com/wikipage?title=NumPy%20and%20SciPy%20for%20.Net
但是这个链接不再存在:
https://store.enthought.com/repo/.iron/
我最近找到了该指令的克隆,并在github上找到了ironpkg-1.0.0.py的克隆.但http://www.enthought.com/repo/.iron/eggs/index-depend.txt已不再存在于互联网上(我用Google搜索,但未找到它)
SciPy for .NET入门
1.)IronPython下载并安装IronPython 2.7,这将需要.NET v4.0.
2.)修改PATH
在路径上添加安装位置,通常是:C:\ Program File\IronPython 2.7
但在64位Windows系统上,它是:C:\ Program File(x86)\ IronPython 2.7
作为检查,打开Windows命令提示符并转到目录(不是上面的目录)并键入:
在.NET 4.0.30319.225上的ipy -V PythonContext 2.7.0.40
3.)ironpkg
Bootstrap ironpkg,它是二进制(基于蛋)Python包的包安装管理器.下载ironpkg-1.0.0.py并键入:
ipy ironpkg-1.0.0.py --install
现在应该可以使用ironpkg命令:ironpkg -h(此处显示一些有用的帮助文本)
4.)scipy
现在安装scipy很简单:
ironpkg scipy numpy-2.0.0b2-1.egg
我想我已尽我所能做到了.任何机构成功为Ironpython27安装numpy和scipy?
我想登录这个网站:https://www.fitbit.com/login 这是我使用的代码:
import urllib2
import urllib
import cookielib
login_url = 'https://www.fitbit.com/login'
acc_pwd = {'login':'Log In','email':'username','password':'pwd'}
cj = cookielib.CookieJar() ## add cookies
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent','Mozilla/5.0 \
                    (compatible; MSIE 6.0; Windows NT 5.1)')]
data = urllib.urlencode(acc_pwd)
try:
    opener.open(login_url,data,10)
    print 'log in - success!'
except:
    print 'log in - times out!', login_url
我使用chrome检查输入框的元素,我尝试了很多密钥对,但没有一个工作.任何人都可以帮我看看这个网站?我在变量acc_pwd中显示的正确数据是什么?
非常感谢你
我想得到一个表的列名,但其中有数百万个数据.所以我不能用:
cursor.execute("SELECT * FROM table_name")
print cursor.description
在sqlite3中,我这样做
crs.execute("PRAGMA table_info(%s)" %(tablename[0]))
for info in crs:
    print info
但这不适用于python mysqldb.谁知道怎么做?
我正在尝试做多变量线性回归.但我发现sklearn.linear_model的工作非常奇怪.这是我的代码:
import numpy as np
from sklearn import linear_model
b = np.array([3,5,7]).transpose() ## the right answer I am expecting
x = np.array([[1,6,9],   ## 1*3 + 6*5 + 7*9 = 96
              [2,7,7],   ## 2*3 + 7*5 + 7*7 = 90
              [3,4,5]])  ## 3*3 + 4*5 + 5*7 = 64
y = np.array([96,90,64]).transpose()
clf = linear_model.LinearRegression()
clf.fit([[1,6,9],
         [2,7,7],
         [3,4,5]], [96,90,64])
print clf.coef_ ## <== it gives me [-2.2  5  4.4] NOT [3, 5, 7]
print np.dot(x, clf.coef_) ## <== it gives me …class test(object):
def __init__(self, a = 0):
    test.a = a
t = test()
print test.a ## obviously we get 0
''' ====== Question ====== '''
print test.somethingelse ## I want if attributes not exist, return None. How to do that?
我想制作自己的 MagicCursor 课程。我希望它从 sqlite3.Cursor() 继承所有方法和属性。但在他的情况下看起来并不那么容易。
通常我们会像这样创建一个游标:
import sqlite3
conn = sqlite3.connect('test.db')
crs = conn.cursor()
因为这中间有联系。所以我想我必须定义我自己的Connection Class,然后定义我自己的Cursor。
这是我想要实现的:
import sqlite3
conn = MyConnect('test.db') ## this returns me a connect object, inherit from         sqlite3.Connection 
crs = conn.cursor() ## this returns me a MyCursor class,
                ## which inherit from sqlite3.Cursor() and has my customized method
这是我的代码,但失败了。
class MyConnect(sqlite3.Connection):
    def cursor(self):
        return MyCursor(self)
class MyCursor(sqlite3.cursor):
    def __init__(self, connect):
        self = connect.cursor()
    def mymethod1(self, argv)
         ...... return ...... ## what ever I defined
任何人都知道如何实现它?
例如,在这段代码中,我希望我的脚本行为是这样的.
当运行到b = a [2]时,或者任何一行都会引发异常,无论什么是异常.我希望脚本停止,并提出一个自定义的红色错误消息,如:'LOL !!!'
如何实现?
try:
    a = [1,2]
    b = a[2]
except:
    raise something
python ×9
numpy ×2
.net ×1
attributes ×1
class ×1
exception ×1
ironpython ×1
javascript ×1
mysql ×1
mysql-python ×1
oop ×1
python-2.7 ×1
scikit-learn ×1
scipy ×1
selenium ×1
sqlite ×1
urllib ×1
urllib2 ×1