xpath

Python: Get html table data by xpath

醉酒当歌 提交于 2021-01-20 20:33:32
问题 I feel that extracting data from html tables is extremely difficult and requires custom build for each site.. I would very much like to be proved wrong here.. Is there an simple pythonic way to extract strings and numbers out of a website by just using the url and xpath of the table of interest? Example: url_str = 'http://www.fdmbenzinpriser.dk/searchprices/5/' xpath_str = //*[@id="sortabletable"] I once had a script that could fetch data from this site. But lost it. As I recall it I was

How to search node by exact text match using Xpath in webdriver

女生的网名这么多〃 提交于 2021-01-20 18:54:31
问题 I need a little help regarding searching an exact text using xpath in webDriver. Suppose i have the html as follows.. <html><body> <table> <tr> <td><button>abcd</button></td> <td><button>abc</button></td> </tr> </table> </body></html> Now i want to click button "abc" I used xpath as //button[contains(text(),'abc')] but it is always performing on button "abcd" as it also contain the text "abc". In this regards I need a predicate or some other procedure which can search exact text instead of

How to use regexp to not match HTML tags that have certain tags inside them? [duplicate]

a 夏天 提交于 2021-01-20 13:49:09
问题 This question already has answers here : Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms (10 answers) RegEx match open tags except XHTML self-contained tags (36 answers) Closed last month . I have a link like this that I want to match with regexp: <a href="tel:something">something</a> I managed to match it with <a[^>]+tel:.*?>.*?<\/a> But I don't want to match links that have <span></span> nested inside them: <a href="tel:[some_numbers]"><span

How to use regexp to not match HTML tags that have certain tags inside them? [duplicate]

十年热恋 提交于 2021-01-20 13:47:18
问题 This question already has answers here : Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms (10 answers) RegEx match open tags except XHTML self-contained tags (36 answers) Closed last month . I have a link like this that I want to match with regexp: <a href="tel:something">something</a> I managed to match it with <a[^>]+tel:.*?>.*?<\/a> But I don't want to match links that have <span></span> nested inside them: <a href="tel:[some_numbers]"><span

How to use regexp to not match HTML tags that have certain tags inside them? [duplicate]

南笙酒味 提交于 2021-01-20 13:47:05
问题 This question already has answers here : Why it's not possible to use regex to parse HTML/XML: a formal explanation in layman's terms (10 answers) RegEx match open tags except XHTML self-contained tags (36 answers) Closed last month . I have a link like this that I want to match with regexp: <a href="tel:something">something</a> I managed to match it with <a[^>]+tel:.*?>.*?<\/a> But I don't want to match links that have <span></span> nested inside them: <a href="tel:[some_numbers]"><span

How to locate style element in Selenium Python?

牧云@^-^@ 提交于 2021-01-20 11:45:08
问题 Hello I want to locate a style element / style elements with Selenium Python, <div style="flex-direction: column; padding-bottom: 65px; padding-top: 0px;"> I tried it in ways like: self.driver.find_elements_by_xpath("//div[@class='flex-direction:column;padding-bottom:835px;padding-top:0px;']/div") But it does not work. So how do I locate these elements using Selenium Python? 回答1: The provided HTML has no class attribute. However in your xpath you have provided class attribute it should be

Why does XPath select nodes outside of context node?

若如初见. 提交于 2021-01-20 07:37:08
问题 I'm using XPath with Node.js and I have the following HTML document, where I want to select all article nodes and then in a second step all divs with class "abc" : <html lang="en"> <head> <meta charset="UTF-8"> <title>Test</title> </head> <body> <article> <div>123456</div> <div class="abc">Hello0!</div> </article> <article> <div>123456</div> <div class="abc">Hello1!</div> </article> <article> <div>123456</div> <div class="abc">Hello2!</div> </article> <article> <div>123456</div> <div class=

How to identify an element through classname even though there are multiple elements with the same classnames using Selenium and Python

☆樱花仙子☆ 提交于 2021-01-20 07:30:11
问题 <div class="_2S1VP copyable-text selectable-text" data-tab="1" dir="ltr" spellcheck="true" contenteditable="true"></div> <div class="_2S1VP copyable-text selectable-text" data-tab="3" dir="ltr" contenteditable="true"></div> I'm a beginner and I've had a hard time distinguishing / specifying the first class over the second one typing = bot.find_element_by_xpath('//div[@class = "_1Plpp"]') this doesn't seem to work and just using the class name always brings up the unwanted second one with the

How to identify an element through classname even though there are multiple elements with the same classnames using Selenium and Python

点点圈 提交于 2021-01-20 07:30:00
问题 <div class="_2S1VP copyable-text selectable-text" data-tab="1" dir="ltr" spellcheck="true" contenteditable="true"></div> <div class="_2S1VP copyable-text selectable-text" data-tab="3" dir="ltr" contenteditable="true"></div> I'm a beginner and I've had a hard time distinguishing / specifying the first class over the second one typing = bot.find_element_by_xpath('//div[@class = "_1Plpp"]') this doesn't seem to work and just using the class name always brings up the unwanted second one with the

Using aria-label to locate and click an element with Python3 and Selenium

风流意气都作罢 提交于 2021-01-20 04:17:55
问题 I want to click or more respectively, expand the "Any time" button. I've tried to locate the element by class_name and xpath. The problem is that the class and xpath are the same for all three 'options'. So, I would like to select and click or expand on that element by using the aria-label. I found a couple of suggestions, but it didn't work for me. Most importantly, I try to do that in python 3. I also tried: driver.find_element_by_xpath(""" //div*[@aria-label='Any Time'] """).click() but it