gpt4 book ai didi

python - 相同的代码在不同的电脑上有不同的结果

转载 作者:行者123 更新时间:2023-11-30 23:09:04 24 4
gpt4 key购买 nike

我可以在我的两台电脑,IOS,WINDOWS上正确运行这些代码,但是在我公司的电脑,Linux上只能找到98个名字。而且他们都使用python 2.7

import requests, bs4  
index_url = 'http://www.nlm.nih.gov/medlineplus/druginfo/herb_All.html'

def get_urls():
response = requests.get(index_url)
soup = bs4.BeautifulSoup(response.text)
#print(response.)
return [a.attrs.get('href') for a in soup.select('div.section-body a[href^=]')]
print(len(get_urls()))

最佳答案

也许确保您使用相同的解析器,并且可以指定您在代码中使用哪个 html 解析器,这样当您在不同的计算机上运行它时,它就会知道要使用哪个解析器。

BeautifulSoup(markup, "html.parser")

文档中提供了有关此内容的更多信息。

关于python - 相同的代码在不同的电脑上有不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31411132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com