我的目的是在输入谷歌搜索词后从第一页的所有链接中提取html.我在代理后面工作,所以这是我的方法.
1.我首先使用mechanize在表单中输入搜索词,我已正确设置代理和机器人.
2.提取链接后,我使用了全局使用urllib2.ProxyHandler的开启工具,单独打开网址.
但是这给了我这个错误.无法搞清楚.
urlopen error [Errno 8] _ssl.c:504: EOF occurred in violation of protocol
Run Code Online (Sandbox Code Playgroud) 嘿,我一直在阅读本教程,了解PyQt4中的拖放方法.但是我无法理解以下几点.如果somepne可以让我更清楚,那就太好了.
def mouseMoveEvent(self, e): //class Button
mimeData = QtCore.QMimeData()
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(e.pos() - self.rect().topLeft())
dropAction = drag.start(QtCore.Qt.MoveAction)
def dropEvent(self, e): //class Example
position = e.pos()
self.button.move(position)
e.setDropAction(QtCore.Qt.MoveAction)
e.accept()
Run Code Online (Sandbox Code Playgroud)
为什么有一个单独的self.button.move()和e.setDropAction()不是self.button.move()实际上移动按钮本身?有人可以解释一下drag.setHotSpot和drag.start()的作用吗?谢谢.
假设我这样做
tweets = api.home_timeline()
Run Code Online (Sandbox Code Playgroud)
它返回一个包含20个最近的tweepy状态对象的列表,这些对象发布在我的时间轴上.如果我这样做的话
for tweet in tweets:
print tweet.text
Run Code Online (Sandbox Code Playgroud)
它打印20条消息.是否可以检索状态发布的时间?状态对象还有哪些其他属性?需要帮助.
我有一个像这样的排序列表
s = [1 , 4 ,6 , 9 ,10 ]
Run Code Online (Sandbox Code Playgroud)
我想知道列表中是否存在数字,或者两个数字之间是否存在数字.如果它出现在两个数字之间,我想打印出来.
现在我的代码看起来像这样
for x in s:
if b == x: \\ b is the number
print b
elif b > x and b < s[s.index(x) + 1] and s.index(x) < len(s):
print b , s[s.index(x) + 1]
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法呢?
我想在没有任何内置 Open-CV 函数的情况下将此 RGB 编码为灰度转换器。这是我的代码的样子
import cv2 , numpy
def GrayConvertor(img):
rows , cols , layers = img.shape
matrix = numpy.zeros((rows , cols))
for i in range(rows):
for j in range(cols):
val = 0.114 * (img[i][j][0]) + 0.587 * (img[i][j][1]) + 0.299 * (img[i][j][2])
fraction = val - int(val)
if fraction >= 0.5:
matrix[i][j] = (int(val) + 1)
else:
matrix[i][j] = int(val)
cv2.imshow("gray" , matrix)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
但是它显示一个空白图像,有什么想法吗?
我发现如何使用教程从谷歌搜索中检索主题的html页面.这在教程中给出.
import mechanize
br = mechanize.Browser()
br.open('http://www.google.co.in')
br.select_form(nr = 0)
Run Code Online (Sandbox Code Playgroud)
直到这一点我理解它才能找回这个表格.然后就是这样
br.form['q'] = 'search topic'
br.submit()
br.response.read()
Run Code Online (Sandbox Code Playgroud)
这会输出与搜索主题相关的页面的html.但我怀疑br.form [parameter]中的这个参数应该是什么?因为我尝试了谷歌新闻,它取得了成功的结果.有人可以帮助我吗?
我想知道检查scipy稀疏矩阵的最佳方法,如果是CSC或CSR.现在我正在使用.
rows, cols = X.shape()
indptr = X.indptr()
if len(indptr) == cols + 1:
print "csc"
else:
print "csr"
Run Code Online (Sandbox Code Playgroud)
谢谢.
我是python机械化的新手,如果有人可以解释为什么会发生这种情况会很好吗?
import mechanize
br = mechanize.Browser()
a = br.open('http://www.google.co.in')
links = br.links()
for link in links:
print link.url
Run Code Online (Sandbox Code Playgroud)
然而,当我再次这样做时,没有任何东西被打印出来
for link in links:
print link.url
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下吗?
这是协方差矩阵的定义。http://en.wikipedia.org/wiki/Covariance_matrix#Definition
矩阵中除主对角线上的每个元素(如果我没记错的话)都简化为E(x_ {i} * x_ {j})-mean(i)* mean(j),其中i和j是行协方差矩阵的数字和列数。
从numpy文档中,
x = np.array([[0, 2], [1, 1], [2, 0]]).T
x
array([[0, 1, 2], [2, 1, 0]])
np.cov(x)
array([[ 1., -1.],
[-1., 1.]])
Run Code Online (Sandbox Code Playgroud)
第一行[0,1,2]对应于X_ {0},第二行[2,1,0]对应于X_ {1}如何计算X_ {0} * X_ {1}的期望,因为不知道随机变量的分布?
谢谢。