The problem is that the path of the HTML selector and xpath.

Asked 1 years ago, Updated 1 years ago, 66 views

Corresponding page: http://lin.popall.com/bbs.htm?code=talking&keyfield=&key=&page=1

Copy the CSS SELECTOR of the table to bring only the part that contains the posts on the free bulletin board There was a problem with the result value of [ ] while working.

The Python we worked on is version 3.7.1. and BS4 and SELENIUM also worked on the latest version.

html=driver.page_source
soup=bs(html, "html.parser")

title_table=soup.select("#popclient > 
                         table:nth-of-type(16) > 
                         tbody > tr > td:nth-of-type(6) > 
                         table:nth-of-type(9)")

I'd appreciate it if you could tell me what the problem is. I beg you.

-------------------------------------------ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

I found the answer.

Selector for a table [ #popclient > table:nth-child(16) > tbody > tr > td:nth-child(6) > table:nth-child(9) ]

xpath in table [ //*[@id="popclient"]/table[5]/tbody/tr/td[6]/table[6] ]

Convert the xpath path to the selector format by checking the part where the path of the selector and the xpath are different.

I solved the problem in the same way as above, but I'm not sure why there's a problem with the value of the selector I copied.

If there is a master you know, please answer.

python-3.x beautifulsoup

2022-09-22 17:57

1 Answers

The #popclient> table:nth-child(16) part of the selector is the 16th of the child elements of the #popclient, and if <table>, it means

In xpath, //*[@id="popclient"]/table[5] means that #popclientchildren are the fifth of the <table> element.


2022-09-22 17:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.