我正在使用selenium.webdriver chrome来抓取我网站上的数据,并希望从访问者那里获取位置。我已成功找到包含'location'的<p>
标签,但它返回None。
需要帮助。非常感谢
我试过.replace(u'\xa0', u' ')
和.remove_space(location).strip()
但是它返回NoneType
对象没有属性'replace'
我的python代码如下
location=browser.find_element_by_xpath('//div[@class="module contact_module expanded"]//p[1]').get_attribute('text')
print(location)
location=location.replace(u'\xa0', u' ')
location=location.remove_space(location).strip()
HTML就在这里
<div class="module contact_module expanded">
<div class="module-header">
<ul class="actions">
<li><a href="#" class="toggle_module" title="Expand / Collapse Section"><i class="icon-collapse-alt" data-expand="icon-expand-alt" data-collapse="icon-collapse-alt"></i></a></li>
</ul>
<h2>Contact <span><a href="#" class="update-module">Edit</a></span></h2>
</div>
<div class="module-content contact-module">
<h4>Email / Phone / Social</h4>
<ul class="contact-list unstyled">
<li class="contact-email">
<i class="fa fa-envelope"></i> <a href="[email protected]" target="_blank">[email protected]</a>
</li>
<li class="contact-phone empty_row"><i class="fa fa-phone"></i> (blank)</li>
</ul>
<h4>Location</h4>
<p>Boondall, Queensland, Australia</p>
<h4>Timezone</h4>
<p>Australia/Brisbane</p>
</div>
</div>
我期待'澳大利亚昆士兰州的Boondall',但实际产量是无
试试这个
location=browser.find_element_by_xpath('//div[@class="module contact_module expanded"]//p[1]').text