为什么此搜索不起作用?

时间:2016-08-26 13:49:22

标签: python search beautifulsoup find

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

这个适用于https://blockchain.info/search?search=422407,找到相关的“0.02269362”:

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=422407").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.023223),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

我在为别人做这件事时遇到了困难。这应该转到方框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

当我尝试使用下面的代码测试脚本的查找部分时,它也不起作用。但是如果你转到https://blockchain.info/search?search=422245并在页面“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

0 个答案:

没有答案