我一直在使用HTMLParser类在Python中使用基本的Web爬虫.我使用修改后的handle_starttag方法获取我的链接,如下所示:
def handle_starttag(self, tag, attrs):
if tag == 'a':
for (key, value) in attrs:
if key == 'href':
newUrl = urljoin(self.baseUrl, value)
self.links = self.links + [newUrl]
Run Code Online (Sandbox Code Playgroud)
当我想找到页面上的每个链接时,这非常有效.现在我只想获取某些链接.
我如何才能获取<td class="title">和</td>标签之间的链接,如下所示:
<td class="title"><a href="http://www.stackoverflow.com">StackOverflow</a><span class="comhead"> (arstechnica.com) </span></td>
Run Code Online (Sandbox Code Playgroud) 我尝试运行以下代码:
lin = ',11'
pat = ',([11|01])$'
re.search(pat, lin)
Run Code Online (Sandbox Code Playgroud)
因为pat有',11'而lin也有',11'我应该得到re.search返回的对象
但在这种情况下,它返回None.
有人可以帮帮我吗?我很困惑.
我正在用 PyQt 制作一个 GUI,我的 MainWindow 类有问题。该窗口不显示我在其他类中定义的小部件,或者它会在左上角显示一小部分小部件,然后切断小部件的其余部分。有人可以帮我解决这个问题吗?
这是一些显示我的问题的示例代码。
import sys
from PyQt4 import QtGui, QtCore
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent=parent)
self.resize(300, 400)
self.centralWidget = QtGui.QWidget(self)
self.hbox = QtGui.QHBoxLayout(self.centralWidget)
self.setLayout(self.hbox)
names = ['button1', 'button2', 'button3']
testButtons = buttonFactory(names, parent=self)
self.hbox.addWidget(testButtons)
class buttonFactory(QtGui.QWidget):
def __init__(self, names, parent=None):
super(buttonFactory, self).__init__(parent=parent)
self.vbox = QtGui.QVBoxLayout()
self.setLayout(self.vbox)
for name in names:
btn = QtGui.QPushButton(name)
self.vbox.addWidget(btn)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
gui = MainWindow()
gui.show()
app.exec_()
Run Code Online (Sandbox Code Playgroud) 我在加载 dll 时遇到了一个新问题。我在加载带有“.so”、“.dll”扩展名的 dll 时没有任何问题。现在我对带有“.a”扩展名的 dll 有一些问题。它是一个静态库。下面是我的代码
Security_dll = ctypes.cdll.LoadLibrary("./staticlibraryname.a")
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我的 os env 是一个 linux open suse。当我尝试这样做时,我得到的确切错误消息是:
File "module3.py", line 3, in <module>
Security_dll = ctypes.cdll.LoadLibrary("./libSecurityProductionStaticlib.a")
File "/usr/lib64/python2.7/ctypes/__init__.py", line 440, in LoadLibrary
return self._dlltype(name)
File "/usr/lib64/python2.7/ctypes/__init__.py", line 362, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ./libSecurityProductionStaticlib.a: invalid ELF header
Run Code Online (Sandbox Code Playgroud) temp = '32'
if temp > 85:
print "Hot"
elif temp > 62:
print "Comfortable"
else:
print "Cold"
Run Code Online (Sandbox Code Playgroud)
为什么输出'热',不应该是'冷'?
我有这个功能,但我不熟悉错误或如何纠正它.
def intify(file1):
numbers=range(0,10)
strnum=[]
for x in numbers:
strnum.append(str(x))
number1=[]
for line in file1:
for split in line.split(' '):
number1.append(split)
listnum=[]
for x in number1:
if x[0] in strnum:
listnum.append(x)
w=map(float, listnum)
#return w
print(w)
Run Code Online (Sandbox Code Playgroud)
错误映射对象位于0x275b990
python ×6
dll ×1
html-parsing ×1
hyperlink ×1
if-statement ×1
linux ×1
loops ×1
parsing ×1
pyqt ×1
python-2.7 ×1
python-3.x ×1
qt ×1
regex ×1
web-crawler ×1