不';在python中进行web爬行时没有响应

不';在python中进行web爬行时没有响应,python,web,web-crawler,Python,Web,Web Crawler,我想得到一份金十字勋章的名单。所以 我发现它的id值是#contentarea _right. 沿着子索引,我编写了以下代码 a_list = soup.select("#contentarea_right > div#box_type_r > table#trend_tab_1 > tbody > tr > td a") or a_list = soup.select("#contentarea_right > div > table#trend_t

我想得到一份金十字勋章的名单。所以

我发现它的id值是#contentarea _right.
沿着子索引,我编写了以下代码

a_list = soup.select("#contentarea_right > div#box_type_r > table#trend_tab_1 > tbody > tr > td a")
or
a_list = soup.select("#contentarea_right > div > table#trend_tab_1 > tbody > tr > td a")
or
a_list = soup.select("#contentarea_right > div > tbody > tr > td a")
or
a_list = soup.select("#contentarea_right > div > table > tbody > tr > td a")

但是什么都没发生。。。如何修复

完整代码

from bs4 import  BeautifulSoup
import urllib.request as req
url = "https://finance.naver.com/sise/"
res = req.urlopen(url)
soup = BeautifulSoup(res, "html.parser")
#contentarea_right > div
a_list = soup.select("#contentarea_right > div#box_type_r > table#trend_tab_1 > tbody > tr > td a")
for a in a_list:
    name = a.string
    print("-",name)

如果我使用较短的选择器

"#contentarea_right #trend_tab_1 a"
然后我得到一些数据


使用不同选择器的示例

from bs4 import  BeautifulSoup
import urllib.request as req

url = "https://finance.naver.com/sise/"
res = req.urlopen(url)
soup = BeautifulSoup(res, "html.parser")

rows = soup.select("#contentarea_right #trend_tab_1 tr")
for row in rows:
    cols = row.select('td')
    print("-", cols[0].text, '|', cols[1].text)
结果

- 청호컴넷 | 3,685
- 한진 | 36,950
- 모다이노칩 | 3,500
- 인터로조 | 28,000
- 티피씨글로벌 | 2,650
- 서연탑메탈 | 2,900
- 아이앤씨 | 5,250
- 바른손 | 2,095
- 한글과컴퓨터 | 10,700
- 금강공업우 | 8,890

box\u type\u r
是一个类,而不是id,该表中没有
tbody
tbody
您在inspector中看到的内容可能是由web浏览器自动生成的。将CSS选择器更改为以下内容


汤。选择(“#contentarea\u right>div.box\u type\u r>table\u趋势选项卡1>tr>td a”)

通常
HTML
没有标签
,但浏览器总是在树中显示它。尝试不使用
t车身
可能会将选择范围缩短。适合我
“#内容区#右侧#趋势(选项卡)1 a”