Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

xpath question

PHP Code

<?php 
<tr >
              <
td><a href="URL">VTC</a><br/>I WANT THIS</td>
              <
td class="paragraph not-important">2017-06-04 12:34</td>
              <
td class="paragraph">0.00019500</td>

                <
td class="grey not-important">
                  
0.00019752
                  
<br/>

                    <
span class="green diff">+1.29%</span>
                </
td>
                <
td class="grey not-important">
                  
0.00019752
                  
<br/>

                    <
span class="green diff">+1.29%</span>
                </
td>
                <
td class="grey ">
                  
0.00019752
                  
<br/>

                    <
span class="green diff">+1.29%</span>
                </
td>
            </
tr> 

I am doing
PHP Code

<?php 
tree
.xpath("//tr/td/text()") 

However I am getting all the numbers and everything. I just need the text "I WANT THIS" after the </br>. The way I am doing it now gives me everything. Note that there are loads of tr. I have just copied one here to make it easier to see.
(Jun 4, 2017 06:14 AM)Skidy Wrote:  
PHP Code

<?php 
<tr >
              <
td><a href="URL">VTC</a><br/>I WANT THIS</td>
              <
td class="paragraph not-important">2017-06-04 12:34</td>
              <
td class="paragraph">0.00019500</td>

                <
td class="grey not-important">
                  
0.00019752
                  
<br/>

                    <
span class="green diff">+1.29%</span>
                </
td>
                <
td class="grey not-important">
                  
0.00019752
                  
<br/>

                    <
span class="green diff">+1.29%</span>
                </
td>
                <
td class="grey ">
                  
0.00019752
                  
<br/>

                    <
span class="green diff">+1.29%</span>
                </
td>
            </
tr> 

I am doing
PHP Code

<?php 
tree
.xpath("//tr/td/text()") 

However I am getting all the numbers and everything. I just need the text "I WANT THIS" after the </br>. The way I am doing it now gives me everything. Note that there are loads of tr. I have just copied one here to make it easier to see.

Check out "BeautifulSoup" for python, then you can do kinda like this
Code
soup = BeautifulSoup(c.get("URL"), headers=headers).content, "lxml")
    tds = soup.findAll("td")
    for td in tds:
        l = BeautifulSoup(str(td), "lxml")
        l.find("a").next // Should get the element after the a
[Image: C1tw29q.png]
(Jun 4, 2017 06:18 AM)Vezel Wrote:  Check out "BeautifulSoup" for python, then you can do kinda like this
Code
soup = BeautifulSoup(c.get("URL"), headers=headers).content, "lxml")
    tds = soup.findAll("td")
    for td in tds:
        l = BeautifulSoup(str(td), "lxml")
        l.find("a").next // Should get the element after the a

Thank you I fiddled with your code as it didn't originally work but now does.

Still would like it just a 1 liner.
PHP Code

<?php 
crypto_platform 
= tree.xpath("//tr/td/text()[preceding-sibling::br]") 

Its a temp solution :)
(Jun 4, 2017 09:19 AM)Skidy Wrote:  Thank you I fiddled with your code as it didn't originally work but now does.

Still would like it just a 1 liner.
PHP Code

<?php 
crypto_platform 
= tree.xpath("//tr/td/text()[preceding-sibling::br]") 

Its a temp solution :)

No problem, yeah I didn't test the code. Just wrote from the top of my head :)

Glad you got it to work!
[Image: C1tw29q.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by ClockismApr 16, 2018 11:03 AM 3 124 Apr 16, 2018 11:03 AM
Last Post: Clockism
[Python] by TriopsFeb 18, 2018 08:47 PM 2 121 Feb 18, 2018 08:47 PM
Last Post: Triops
[Python] by TriopsJun 2, 2017 08:25 PM 4 168 Jun 2, 2017 08:25 PM
Last Post: Triops