Python 为什么这个搜索不起作用?

Python 为什么这个搜索不起作用?,python,search,beautifulsoup,find,Python,Search,Beautifulsoup,Find,我的目标是让这个Python脚本在blockchain.info上打开一个块编号页面,并获取正确的表。然后在此表中搜索一系列值和打印的结果 这一个工作,查找关联的“0.02269362”: 我很难为别人做这件事。这应该转到422245块并找到“0.02972821”。它不打印任何东西。理想情况下,它将打印与[x.xxxx]yz匹配的任何内容,以此类推 import numpy as np from bs4 import BeautifulSoup import urllib2 #create

我的目标是让这个Python脚本在blockchain.info上打开一个块编号页面,并获取正确的表。然后在此表中搜索一系列值和打印的结果

这一个工作,查找关联的“0.02269362”:

我很难为别人做这件事。这应该转到422245块并找到“0.02972821”。它不打印任何东西。理想情况下,它将打印与[x.xxxx]yz匹配的任何内容,以此类推

import numpy as np
from bs4 import BeautifulSoup
import urllib2

#create a list of numbers that will be used in search 
list = np.arange(0.9749999312,0.9793780897,0.000001)

#open webpage, get table 
web = urllib2.urlopen("https://blockchain.info/search?search=422245").read()  #whole page 
soup = BeautifulSoup(web, "lxml")
table = soup.findAll("table", {'class':'table table-striped'}) #Correct table 

#Go through all numbers created; check if found; print found 
for i in list: 
j = str(round((i * 0.03044589),8))
for line in table: #if you see a line in the table
    if line.get_text().find(j) > -1 : #and you find the specific string
        print(line.prettify().encode("utf-8")) #print it
        print j
当我尝试使用下面的代码测试脚本的查找部分时,它也不起作用。但如果您转到并在“0.02972821”页上搜索,则该值存在。我不明白为什么这不起作用

import numpy as np
from bs4 import BeautifulSoup
import urllib2

#create a list of numbers that will be used in search 
list = np.arange(0.9749999312,0.9793780897,0.000001)

#open webpage, get table 
web = urllib2.urlopen("https://blockchain.info/search?search=422245").read()  #whole page 
soup = BeautifulSoup(web, "lxml")
table = soup.findAll("table", {'class':'table table-striped'}) #Correct table 

#Go through all numbers created; check if found; print found 
j = "0.02972821"
for line in table: #if you see a line in the table
if line.get_text().find(j) > -1 : #and you find the specific string
    print(line.prettify().encode("utf-8")) #print it
    print j

您是否尝试过对脚本进行一些基本调试?i、 e.打印
表格
的内容以查看其外观是否正确,在循环时打印每行,等等?如果这会产生太多的输出而无法处理,您可以将html内容保存为本地文件,并对其进行编辑以删除所有无关信息,只留下您关心的行。@JohnGordon我认为问题在于“soup=BeautifulSoup(web,“lxml”)”行。Web是整个页面,但soup是该页面的有限版本,因此限制了找到的表的数量。我将“lxml”更改为“html.parser”,现在选择了所有正确的数据。您是否尝试过对脚本进行一些基本调试?i、 e.打印
表格
的内容以查看其外观是否正确,在循环时打印每行,等等?如果这会产生太多的输出而无法处理,您可以将html内容保存为本地文件,并对其进行编辑以删除所有无关信息,只留下您关心的行。@JohnGordon我认为问题在于“soup=BeautifulSoup(web,“lxml”)”行。Web是整个页面,但soup是该页面的有限版本,因此限制了找到的表的数量。我将“lxml”更改为“html.parser”,现在选择了所有正确的数据。
import numpy as np
from bs4 import BeautifulSoup
import urllib2

#create a list of numbers that will be used in search 
list = np.arange(0.9749999312,0.9793780897,0.000001)

#open webpage, get table 
web = urllib2.urlopen("https://blockchain.info/search?search=422245").read()  #whole page 
soup = BeautifulSoup(web, "lxml")
table = soup.findAll("table", {'class':'table table-striped'}) #Correct table 

#Go through all numbers created; check if found; print found 
j = "0.02972821"
for line in table: #if you see a line in the table
if line.get_text().find(j) > -1 : #and you find the specific string
    print(line.prettify().encode("utf-8")) #print it
    print j