BeautifulSoup is not extracting the div I want properly. I am not sure what I am doing wrong. Here is the html:
<div id='display'>
<div class='result'>
<div>text0 </p></div>
<div>text1</div>
<div>text2</div>
</div>
</div>
And here is my code:
div = soup.find("div", {"class": "result"})
print(div)
I am seeing this:
<div class="result">
<div>text0 </div></div>
What I am expecting is this:
<div class="result">
<div>text0</div>
<div>text1</div>
<div>text2</div>
</div>
This works as expected if I remove the </p> tag. In other words, the </p> tag seems to be throwing the parser off.
Edit:
This works as expected on Python 2.7.12, beautifulsoup4 version 4.5.1. But does not work on Python 3.6.4, beautifulsoup4 version 4.7.1. Not sure if the culprit is python version or bs4 version (more likely).
Can someone please help?
I see no problem using select
from bs4 import BeautifulSoup as bs
html = '''
<div id='display'>
<div class='result'>
<div>text0 </p></div>
<div>text1</div>
<div>text2</div>
</div>
</div>
'''
soup = bs(html)
soup.select('.result')
Related
I have created a snippet to convert the tex commands to expressions and while the snippet is added to the CMS page, the commands are converting into expressions but its getting disappears after a few seconds.
Also, I have tried dynamically by adding the command through js and converting it using the MathJax.typeset() and MathJax.Hub.Queue(['Typeset', MathJax.Hub, tag]);.
But still, the same problem occurs and if we try to add the MathJax js in the snippet then the expressions are displayed multiple times.
Please find the below snippet and help us on finding the issue.
<template id="mathjax_form_12" name="Mathjax">
<section>
<t t-call="web.layout">
<div class="section">
<div class="section-contact">
<div class="container">
<div class="contact-form">
<p>
When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\]
$$f(x,y)=\int_0^\infty dp\int_0^\infty dq \frac{pqf(p,q)}{\sqrt{x^2+y^2}}$$
</p>
</div>
</div>
</div>
</div>
<script>
(function(){
MathJax = {
tex: {
inlineMath: [['$'], ['\\(',')']],
packages: ['base', 'newcommand', 'configMacros']
},
};
})();
</script>
<script async="1" src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_SVG'></script>
</t>
</section>
</template>
Thanks!!
I have googled this extensively but can't get to an answer, I'm trying to extract "90,856" in the title. It's value changes over time:
<div class="card hreddeep">
<div class="card-header hbuilt">
<div class="card-body">
<div class="row">
<div class="col-6 text-left">
<div class="h6 text-uppercase param-title">Search<br>Volume</div>
<div class="h4 param-content" title="90,856">
my code is:
find_element_by_xpath("//div[#class='h4-param-content']").get_attribute("title")
grateful for some help. Thanks
Your XPath contains a typo (according to your sample data) : h4-param instead of h4 param...
First, test with :
find_element_by_xpath("//div[#class='h4 param-content']").get_attribute("title")
If it doesn't work, try with an expected condition.
Add the following imports :
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Code :
wait = WebDriverWait(driver, 10)
output = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[#class='h4 param-content']"))).get_attribute("title")
print(output)
Any one who have experience an error when you are using IE. Can you help with this scenario for possible alternative or fix.
I have fixed this problem this way, here an example:
Change your interpolation from this
<div class="message">
<p>{{ error_message }}</p>
</div>
to this:
<div class="message">
<p v-text="error_message"></p>
</div>
Protractor Code to access the repeater which i am using is below
element.all(by.repeater('x in parked'));
HTML Code
<div class="row content">
<div class="col-sm-2">
<div ng-show="role != 3">
<label for="parked" style="color:#0000ff;font-weight:bold">PARKED</label>
<ul style="color:#006400;font-weight:bold" class="arriv-depart">
<li ng-repeat="x in parked" popover-placement="top" data-popover-template="dynamicPopover3.templateUrl" data-popover-trigger="mouseenter">{{ deviceData[x[0]].boatName + ':' + deviceData[x[0]].ownerName}}</li>
</ul>
</div>
</div>
</div>
The problem is, protractor throws a warning:
W/element - more than one element found for locator by.repeater("x in parked") - the first result will be used.
I need to display all the elements present in Parked.
It looks like you have multiple "x in parked" repeaters so the warning isn't telling you that it found multiple "x's", but that it found multiple "x in parked".
Protractor docs say to avoid Xpath, but I have found it to solve countless problems for me especially when it comes to repeaters.
I'm working on a project for Prestashop and I have the following file:
blocktopmenu.tpl
https://github.com/PrestaShop/PrestaShop/blob/master/modules/blocktopmenu/blocktopmenu.tpl
I need to know where is the end tag for "sf-contener clearfix" < / div >
Any idea?
Thks and sorry my english!
------ EDITED POST ------
i tried it, but no work for me :(((
I placed "exampleDiv" right here:
header.tpl
<div id="header_right" class="grid_6 omega">
{$HOOK_TOP}
<div id="exampleDiv"></div>
</div>
but i look this result in Firebug:
<div id="header" class="grid_9 alpha omega">
<a id="header_logo" href="#"></a>
<div id="header_right" class="grid_6 omega">
<div id="topMenu_bg_up"></div>
<div class="sf-contener clearfix"></div>
**i wanna to play here :D**
</div>
<div id="minic_slider" class="theme-default"></div>
<div style="display:none;">
<div>
<script type="text/javascript">
<div id="exampleDiv"></div>
**but it work in this other place :(**
</div>
</div>
Here :
https://github.com/PrestaShop/PrestaShop/blob/master/themes/default/header.tpl#L84
The #header_right is closed in blocktopmenu.tpl and the topmenu is displayed under.
Edit : If you want to add content just after the topmenu, the best way is to create e module, hook it on toppage and position it just after the blocktopmenu.