我正在使用BS4和PhantomJS来抓取网站。在Mac上一切正常但在Windows上我遇到了一个奇怪的错误:find_all()
返回None
,但元素存在!
我的代码:
def get_venues():
driver = webdriver.PhantomJS(executable_path = path)
url=web+'#/racing'
driver.get(url)
try:
wait = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CLASS_NAME, "wrapper")))
finally:
content=driver.page_source
soup=bs4.BeautifulSoup(content, "html5")
driver.quit()
b = soup.find(id='content').div
print(b)
c = b.ul(attrs={'class': 'main-list'})
print(c)
且c
为None
,b
的情况不应如此:
</ul></div><ul class="main-list"><li><div class="collapsible R"><div class="icon race_code_R"></div><span>Thoroughbreds</span><div class="arrow_down_sign"></div></div><ul class="sub-list"><li class="venue cell"><a href="#/meetings/19197">
<span class="location">Beaudesert</span>
<div class="goto-sign"></div>
</a>
<a class="next-race" href="#/races/181880/exchange/win">
<span class="time-left critical">-30m</span>
<span class="number">R5</span>
</a>
</li><li class="venue cell"><a href="#/meetings/19199">
<span class="location">Werribee</span>
<div class="goto-sign"></div>
</a>
<a class="next-race" href="#/races/181900/exchange/win">
<span class="time-left critical">-38s</span>
<span class="number">R7</span>
</a>
</li><li c
答案 0 :(得分:1)
答案 1 :(得分:0)
b.ul
适用于Windows
但b.ul(attrs={'class': 'main-list'})
没有。
你必须使用,
c = b.find("ul",attrs={'class': 'main-list'})
我无法解释为什么会发生这种情况: - )
希望有所帮助。