我安装了numpy
sudo apt-get install numpy
Run Code Online (Sandbox Code Playgroud)
然后在python2.7中导入numpy
import numpy
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 45, in <module>
from numpy.testing import Tester
File "/usr/local/lib/python2.7/dist-packages/numpy/testing/__init__.py", line 8, in <module>
from unittest import TestCase
ImportError: cannot …Run Code Online (Sandbox Code Playgroud) 我试图从www.flipkart.com抓取所有手机.现在,我想到的是我可以从这里刮掉所有手机.
http://www.flipkart.com/mobiles/pr?p[]=sort%3Dprice_asc&sid=tyy%2C4io&layout=grid
Run Code Online (Sandbox Code Playgroud)
现在,问题是,在这个网站上我必须按" 显示更多结果 "才能看到更多结果.但是,我怎么能用代码呢?我在python中使用BeautifulSoup包.
我的代码到现在为止:
import bs4
import re
import urllib2
import sys
link = 'http://www.flipkart.com/mobiles/pr?p[]=sort%3Dprice_asc&sid=tyy%2C4io&layout=grid'
response = urllib2.urlopen(link)
thePage = response.read()
soup = bs4.BeautifulSoup(thePage)
allMobiles = soup.find('div', attrs={'id': 'products'})
Run Code Online (Sandbox Code Playgroud)
我只得到输出的第一页?我如何访问其他页面?
我想为我的网站创建一个推荐引擎.假设用户来到我的网站.我想向他推荐他能看到的其他产品.我可以创建一个推荐引擎.但是,如何找到模式?我所想的是,如果无论如何我都能知道用户浏览了哪些产品,我可以在其中找到一个模式并向另一个用户建议.但是,如果不让用户登录,这种信息跟踪是否可行?跟踪IP地址可能是单向的,但IP可能是动态的.我听说过饼干.请帮我.有没有这方面的API?
我有一个对象
public class Point{
int x, y;
Point(int x, int y){
this.x = x;
this.y = y;
}
public String toString(){
String ret = "[";
ret += Integer.toString(x);
ret += ", ";
ret += Integer.toString(y);
ret += "]";
return ret;
}
}
Run Code Online (Sandbox Code Playgroud)
我已经能够用Gson反序列化这个对象了:
class PointDeserializer implements JsonDeserializer<Point>{
@Override
public Point deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
Gson gson = new Gson();
int[] tmp = gson.fromJson(json, int[].class);
int a = tmp[0];
int b = tmp[1];
return new Point(a,b); …Run Code Online (Sandbox Code Playgroud) 真的是它应该的样子还是有什么问题?
我这样做很简单,就像文档中提到的那样:
response = requests.post(path, client_id=self.app_id, client_secret=self.app_secret, grant_type="client_credentials")
Run Code Online (Sandbox Code Playgroud)
的输出response.request.headers是
{'Content-Length': '0', 'User-Agent': 'python-requests/2.4.1 CPython/2.7.5 Darwin/13.3.0', 'Connection': 'keep-alive', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate'}
Run Code Online (Sandbox Code Playgroud)
我正在做的错误是什么?
我有一个网站,当我向下滚动时会生成更多产品.与其他网站不同,firebug控制台中没有任何内容.所以,我使用selenium来模拟浏览器.我已经使它工作,但与Firefox驱动程序.但是,由于我正在托管在命令行上运行的Web服务器,因此我使用的是HTMLUNIT.有人能告诉我如何使用HTMLUNIT滚动页面吗?这是现在的代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Remote("http://127.0.0.1:4444/wd/hub",desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS)
browser.get("http://www.somewebsite.com/")
x = browser.find_elements_by_xpath("//div[@id='containeriso3']/div/a[1]")
hrefs = [i.get_attribute('href') for i in x]
print len(hrefs)
time.sleep(2)
browser.execute_script("scroll(0, 2500);")
time.sleep(2)
x = browser.find_elements_by_xpath("//div[@id='containeriso3']/div/a[1]")
hrefs = [i.get_attribute('href') for i in x]
print len(hrefs)
Run Code Online (Sandbox Code Playgroud)
谢谢.
假设我有一堂课Point。当我做:
Class myClass = Class.forName("Point");
Run Code Online (Sandbox Code Playgroud)
有用。但是当我这样做时:
Class myNewClass = Class.forName("[L" + "Point");
Run Code Online (Sandbox Code Playgroud)
这是行不通的。可以做些什么来使这项工作?
我有一个名为Homeclass的类,它是我的app的父类.现在,我想在某个地方初始化这个类,这样我就可以从任何地方访问类中的所有内容.该应用程序的起点是RootViewController.我应该在起点初始化应用程序吗?如果是,我应该怎么做才能从应用程序的任何地方访问它?