相同的代码在不同的计算机上不同的结果
Same code different result on different computers
我可以 运行 在我的两台计算机 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")
文档中有关于此的更多信息。
我可以 运行 在我的两台计算机 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")
文档中有关于此的更多信息。