所以,我基本上要做的是,找到一个特定页面的链接(这里是10)。一切都很好,我甚至正确地得到了索引(startlink,startquote,endquote)。但是,URL不能打印。为什么会这样呢?那么,哪里出了问题呢?如果你能改正它,我会很高兴!
def web():
n=0
a=open('quora.txt', 'r') #I've saved it as a txt file in my system
b=a.read()
startlink=0
while(n<10):
startlink=b.find('<a href=', startlink+1)
startquote=b.find('"', startlink)
endquote=b.find('"', startquote)
url=b[startquote+1:endquote]
print url, startlink, startquote, endquote
n=n+1这是我得到的输出,只有索引。否,URL
4506 4514 4514
5308 5316 5316
5357 5365 5365
5472 5480 5480
5515 5523 5523
5588 5596 5596
5639 5647 5647
5723 5731 5731
6828 6836 6836
6867 6875 6875发布于 2013-08-15 20:35:25
搜索结束引号时,应从起始引号位置后的一个字符开始:
def web():
n = 0
a = open('quora.txt', 'r') #I've saved it as a txt file in my system
b = a.read()
startlink = 0
while (n < 10):
startlink = b.find('<a href=', startlink + 1)
startquote = b.find('"', startlink)
endquote = b.find('"', startquote + 1)
url = b[startquote + 1:endquote]
print url, startlink, startquote, endquote
n = n + 1因为现在它也与结束引号的相同起始引号匹配
https://stackoverflow.com/questions/18252595
复制相似问题