xpath Located <p> but return None - html

I'm using selenium.webdriver chrome to crawl data from my website, and want to get the location from visitors.
I have successfully located the <p> label which contains 'location', but it return None.
Need help here. Many Thanks
I have tried .replace(u'\xa0', u' ') and .remove_space(location).strip() but it returns NoneType object has no attribute 'replace'
my python code is below
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 is here
<div class="module contact_module expanded">
<div class="module-header">
<ul class="actions">
<li><i class="icon-collapse-alt" data-expand="icon-expand-alt" data-collapse="icon-collapse-alt"></i></li>
</ul>
<h2>Contact <span>Edit</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> df#hotmail.com
</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>
I expected 'Boondall, Queensland, Australia' but the actual output is None

Try this
location=browser.find_element_by_xpath('//div[#class="module contact_module expanded"]//p[1]').text

Related

How to import price value to Google Sheets from a website using ImportXML function?

I'm trying to use ImportXML on Google Sheets to import a price value from a website. Can't find the right XPATH. Please help!
I tried this line and various others and they didn't work:
=importxml("http://www.bizportal.co.il/mutualfunds/quote/giusimandpedionot/5124573","//div[#class='top-area-cube']//num()")
This is the relevant source of the page I'm trying to extract (I want the value 117.3, under the data-row mutual-funds"/"top-area-cube"/"num section).
<a class="add-to-portfolio " href="javascript:void(0);" onclick="portfolio.addPaper('5124573',this)" data-paper-added="0" data-user-logged="0" data-paper-id="5124573" data-name="quote-paper">
<span class="label">הוסף לתיק אישי</span>
<span class="icon-case2"></span>
</a>
<h1 class="data-row">
<span class="paper-name">תכלית MSCI WORLD TTF</span>
</h1>
<div class="data-row mutual-funds">
<div class="top-area-cube">
<div class="label">מחיר פדיון</div>
<div class="num">117.33</div>
</div>
<div class="top-area-cube">
<div class="label">מחיר קנייה</div>
<div class="num">117.33</div>
</div>
<span class="num percent rise"><span>0.35%</span><span class="icon icon-up"></span></span>
<span class="num percent points-container rise"></span>
</div>
<div class="statistics-container">
<ul class="row data-row statistics">
<li><span class="label">% החודש:</span><span class="num rise">3.69%</span></li>
<li><span class="label">% השנה:</span><span class="num rise">14.33%</span></li>
<li><span class="label">% 3 חודשים:</span><span class="num rise">8.51%</span></li>
<li><span class="label">% 12 חודשים:</span><span class="num rise">6.74%</span></li>
<li><span class="label">סטיית תקן (שנה):</span><span class="num">12.11</span></li>
<li><span class="label">שארפ (שנה):</span><span class="num">0.54</span></li>
</ul>
</div>
The expected results are the value 117.33 (or any other value under this specific node) to return to the google sheets file.
The current result is #N/A
unfortunately, this site can't be scraped with any IMPORT formula, most likely due to anti-scraping measurements they took to promote their API

calling different html pages using href

I'm trying to call different HTML pages through href in tag after running flask file .But it's giving
Not found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. where am i going wrong.
` index.html
<section>
<nav>
<ul>
<li><a href="index.html" class="button js-button" role="button">
<i class="fa fa-file" aria-hidden="true"></i> File </a></li>
<br><br>
<li><i class="fa fa-file-image-o" aria-hidden="true"></i> Image</li>
<br><br>
<li><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> Text </li>
</ul>
</nav>
`
app.py
app = Flask(__name__)
app.secret_key = 'random string'
#app.config['UPLOAD_FOLDER'] = 'templates/'
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
#app.route('/')
def home():
return render_template('index.html')
Try this:
<a href="{{ url_for('index.html') }}" class="button js-button" role="button">
More about templating can be found here: http://flask.pocoo.org/docs/1.0/templating/

iMacros - TAG specific element with XPATH

and thank you in advance for taking a minute of your valuable time to solve this puzzle and educate me on the topic.
(please forgive my terminology)
I am using the following code in iMacros for Firefox to select an element on the site, which works fine, as long as the element exists and is in the same order.
TAG XPATH=".//*[#id='contacts']/ul/li[1]/div/ul/li[1]" EXTRACT=TXT
Which in this case would result in "New York, NY"
From:
<div id="contacts" class="article expanding_group">
<div class="article-header">
<!-- Public Company = Block. Public Name/Title = Restricted. -->
<ul class="list">
<li class="list_item">
<div class="list_item_content contact-detail">
<div class="edit expanded">
<ul>
<li class="name"> New York, NY </li>
<li class=" ellipsis">
http://www.a24films.com
</li>
<li class="info ">
+1 646 568 6015
<span class="attributes">phone</span>
</li>
<li class="info ellipsis">
info#a24films.com
</li>
<li class="address ">601 West 26th Street</li>
<li class="address ">Suite 1740</li>
<li class="address "> New York, NY 10001 </li>
<li class="address ">USA</li>
<li class="address ">
</ul>
</div>
However, if the field is missing, it will skip to the next field which will, in essence, result in data being inserted into the incorrect row.
E.g. if I am expecting columns "name, phone, address", and it is missing phone, it will result in "name, address, blank".
I can see it I want only when list item 1's class="name", so my question is: is there a way to specify that I want the list item number 1 that contains "name" in class?
I have tried a variation of strings to no avail, but I woulf imaging something like this is possible:
TAG XPATH=".//*[#id='contacts']/ul/li[1]/div/ul/li[1]/name" EXTRACT=TXT
Thank you for your time,
Reinaldo
You can try the following code:
TAG XPATH=".//*[#id='contacts']/ul/li[1]/div/ul/li[#class='name'][1]" EXTRACT=TXT
Try this Xpath:
.//*[#id='contacts']//li[#class='name'][1]
I don't think #Shugar's code will work.

how to simplify template?

how to simplify template in angularjs? Here there are three different variants lie within podgruzki data objects, but depending on different objects IF loaded with different sets of properties. Is it possible to simplify both the template
<div class="suggest" ng-show="showSuggest" ng-if="$ctrl.Name == 'A'">
<ul class="height-list">
<li ng-repeat="node in $ctrl.Searched()" ng-mousedown="add(this)">
<span ng-attr-title="{{node.a}}">{{node.a}}</span>
</li>
</ul>
</div>
<div class="suggest" ng-show="showSuggest" ng-if="$ctrl.Name == 'B'">
<ul class="height-list">
<li ng-repeat="node in $ctrl.Searched() " ng-mousedown="add(this)">
<span ng-attr-title="{{node.b}}">{{node.b}}</span>
</li>
</ul>
</div>
<div class="suggest" ng-show="showSuggest" ng-if="$ctrl.Name == 'C'">
<ul class="height-list">
<li ng-repeat="node in $ctrl.Searched()" ng-mousedown="add(this)">
<span ng-attr-title="{{node.C}}">{{node.C}}</span>
</li>
</ul>
</div>
Let's say you normalize your node and name to be 1 to 1. So if your controller name is "a" or "Foo", then your node will have a property named a or Foo.
Then you will be able to reduce your template to the following:
<div class="suggest" ng-show="showSuggest">
<ul class="height-list">
<li ng-repeat="node in $ctrl.Searched()" ng-mousedown="add(this)">
<span ng-attr-title="{{node[$ctrl.Name]}}">{{node[$ctrl.Name]}}</span>
</li>
</ul>
</div>

"Text not allowed in element ul in this context"

Text not allowed in element ul in this context
I do not understand this error message from the markup validation service and I have been unable to find an answer.
My code is here:
<ul class="blog-meta">
<li><p><i class="fa fa-user"></i> Admin</p></li> |
<li><p><i class="fa fa-clock-o"></i> April 24th,2014</p></li> |
<li><p><i class="fa fa-tags"></i>creative , wordpress</p></li> |
<li><p><i class="fa fa-comments"></i> 0 Comments</p></li>
</ul>
I guess this error is due to this "|" remove it and validate it again.
To solve this write it inside <li> </li>
<ul class="blog-meta">
<li><p><i class="fa fa-user"></i> Admin | </p></li>
</ul>