将.ini文件解析为BeautifulSoup find_all()方法

时间:2017-06-28 07:36:18

标签: python bs4

def test():
    config = configparser.ConfigParser()
    #reading my .ini file
    config.read('config.ini')
    url = "https://en.wikipedia.org/wiki/Test"
    r = requests.get(url)
    soup = BeautifulSoup(r.content, "lxml")
    #retrieving "data" from section "MarketPlace" 
    # data = "a" in this context
    data = config.get("MarketPlace", "data")
    #call soup.find_all to find "a"
    #Expect text = soup.find_all("a")
    text = soup.find_all(data)
    for everything in text:
        #print all text in wikipedia
        print(everything)

我正在用上面的方法试验配置文件。代码假定打印所有文本,但没有打印任何内容。我不确定为什么它不起作用。正如data = "a"我假设soup.find_all(data)中的数据为soup.find_all("a")。任何人都能向我解释为什么会发生这种情况?或者我错过了什么?

0 个答案:

没有答案