๋ฐ์ํ
ํต์ฌ :
select ๋ก ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ฌ ๋, ์์ ๊ฐ์ ๋ฆฌ์คํธ๋ก ๋ฐํ์ด๋จ!!
์ ํ๋ธ href ์ฌ์ดํธ ๋งํฌ ํฌ๋กค๋ง ํ๊ธฐ
์์์ ์์ฑ ๊ฐ์ ธ์ค๊ธฐ
์ ๋ ๋ ์ด์ฉ
drver.find_element_by_xpath ์์
url1 = driver.find_element_by_xpath('/html/body/ytd-app/div/ytd-page-manager/ytd-search/div[1]/ytd-two-column-search-results-renderer/div/ytd-section-list-renderer/div[2]/ytd-item-section-renderer[1]/div[3]/ytd-video-renderer[1]/div[1]/div/div[1]/div/h3/a')
url1.get_attribute('href')
๊ฒฐ๊ณผ
'https://www.youtube.com/watch?v=RL5oHFPxQE0'
์ฌ์ฉํ๋ฉด ์๋๋ ์ฝ๋
# ๋ทฐํฐํ์ํ๋ก ํฌ๋กค๋ง ์ํ
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
aa = soup.select('#title-wrapper > h3 a')
for a in aa:
print(a['href'])
ํ๋์ฉ ๊ฐ์ ๋ถ๋ฌ์์ ๋ฆฌ์คํธ ๊ฐ์ธ์ง, ์์๋ก ๋ถ๋ฌ์์ผํ๋์ง ํ์ ํ๊ธฐ
soup.select('#container > h1')
๊ฒฐ๊ณผ
[<h1 class="title style-scope ytd-video-primary-info-renderer">
<yt-formatted-string class="style-scope ytd-video-primary-info-renderer"
force-default-style="">Kia EV6 | Iris 20"</yt-formatted-string></h1>]
์ฝ๋ 2
soup.select('#container > h1')[0]
๊ฒฐ๊ณผ
<h1 class="title style-scope ytd-video-primary-info-renderer">
<yt-formatted-string class="style-scope ytd-video-primary-info-renderer" force-default-style="">
Kia EV6 | Iris 20"</yt-formatted-string></h1>
๋ฐ์ํ
'๐๏ธ์ํํธ์จ์ด > ๐ปpython' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํฌ๋กค๋ง ์ ๋ ๋ ๊ธฐ๋ฅ๋ค - ํฌ๋กค๋ฌ ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ (0) | 2021.11.26 |
---|---|
Only the following pseudo-classes are implemented: nth-of-type. ์๋ฌ(error) (0) | 2021.11.25 |
'list' object has no attribute 'find_all' ์๋ฌ (0) | 2021.11.25 |
[Python] TypeError: 'NoneType' object is not iterable ์ค๋ฅ ํด๊ฒฐ ๋ฐฉ๋ฒ (0) | 2021.11.25 |
[python] ํ์ด์ pd.concat (0) | 2021.11.25 |