Python 将.ini文件解析为BeautifulSoup find_all()方法
我正在用上述方法试验配置文件。代码应该打印所有文本,但没有打印任何内容。我不知道为什么它不起作用。作为Python 将.ini文件解析为BeautifulSoup find_all()方法,python,bs4,Python,Bs4,我正在用上述方法试验配置文件。代码应该打印所有文本,但没有打印任何内容。我不知道为什么它不起作用。作为data=“a”我假设soup.find_all(data)中的数据是soup.find_all(“a”)。有人能向我解释为什么会这样吗?还是我遗漏了什么?如果soup.find_all(“a”)有效,而soup.find_all(data)无效,那么显然data!=“a”。所以打印出数据,看看它到底是什么。请尝试打印(repr(data))以便更容易发现尾随空格等内容。@smarx谢谢您的建议
data=“a”
我假设soup.find_all(data)
中的数据是soup.find_all(“a”)
。有人能向我解释为什么会这样吗?还是我遗漏了什么?如果soup.find_all(“a”)
有效,而soup.find_all(data)
无效,那么显然data!=“a”
。所以打印出数据
,看看它到底是什么。请尝试打印(repr(data))
以便更容易发现尾随空格等内容。@smarx谢谢您的建议!你可以这样回答,我会接受的。
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)