【发布时间】:2020-08-25 14:23:02
【问题描述】:
我正在尝试在网页上抓取一个表格,我想将其转换为 pandas DataFrame。我试图抓取的页面需要身份验证,但我已经设法使用请求包传递它。接下来,我想刮桌子,我发现使用 Chrome 中的开发工具。我已经复制了选择器并将其传递给了汤选择器()方法。但是,当我打印出来时,它会返回一个空字符串。我尝试了几种不同的方法,但都没有给我我非常想要的桌子。我究竟做错了什么?这是我的代码:
import requests
from bs4 import BeautifulSoup as bs
cookies = {
#some information
}
headers = {
#some information
}
params = (
#some information
)
response = requests.get('http://www.hctiming.com/myphp/resources/login/browse_results.php?live_action=yes&smartphone_action=no', headers=headers, cookies=cookies, verify=False)
soup = bs(response.content, features="lxml")
test = soup.select("#fis_result_content0 > div.row.racers-list-tab.ranking > div > div > table")
print(test)
这是我在 chrome 中的 dev.tools 的屏幕截图,只是为了让您了解我的桌子在哪里:
【问题讨论】:
-
managed to pass it using the request package是什么意思。我没有在 response.content 中看到表格 -
我的意思是我已经成功地进行了身份验证。就这样
-
好的。很好地提供能够做到这一点的代码。您拥有的代码没有通过身份验证(或至少在我这边)
标签: python pandas beautifulsoup