第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從列表中獲取特定鏈接

從列表中獲取特定鏈接

慕妹3242003 2023-10-24 21:44:40
我想打印前 5 個(gè)“分組”中第二個(gè)標(biāo)簽的文本,并選擇后五個(gè)“分組”中的第一個(gè)。我該怎么做?https://www.carehome.co.uk/care_search_results.cfm/searchunitary/Tower-Hamletsfrom urllib.request import urlopen as uReqfrom bs4 import BeautifulSoup as soupfrom selenium import webdriver#grabspage and parses it through ready for picking apartmy_url = "https://www.carehome.co.uk/care_search_results.cfm/searchunitary/Tower-Hamlets"driver = webdriver.Chrome(executable_path='C:/Users/lemonade/Documents/work/chromedriver')driver.get(my_url)page_s = soup(driver.page_source, features='html.parser')#Finds relvant divscontainers = page_s.findAll("div", {"class": "home-name"})for container in containers:    name_container = container.p    all_a = name_container.findAll("a")    print(all_a)輸出:[<a name="member_21310"></a>, <a href="https://www.carehome.co.uk/carehome.cfm/searchazref/20001005SILA" style="font-weight:bold;font-size:28px">Silk Court</a>][<a name="member_35665"></a>, <a href="https://www.carehome.co.uk/carehome.cfm/searchazref/10001005FITA" style="">Westport Care Home</a>][<a name="member_34393"></a>, <a href="https://www.carehome.co.uk/carehome.cfm/searchazref/20001005ASPA" style="font-weight:bold;font-size:28px">Aspen Court Care Home</a>][<a name="member_4936"></a>, <a href="https://www.carehome.co.uk/carehome.cfm/searchazref/10001005SYDA" style="">Beaumont Court</a>][<a name="member_40189"></a>, <a href="https://www.carehome.co.uk/carehome.cfm/searchazref/20001005HAWA" style="font-weight:bold;font-size:28px">Hawthorn Green Residential and Nursing Home</a>]
查看完整描述

2 回答

?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以使用 css 選擇器來(lái)執(zhí)行此操作select(),它將返回預(yù)期的輸出。


from bs4 import BeautifulSoup as soup

from selenium import webdriver


#grabspage and parses it through ready for picking apart

my_url = "https://www.carehome.co.uk/care_search_results.cfm/searchunitary/Tower-Hamlets"


driver = webdriver.Chrome(executable_path='C:/Users/lemonade/Documents/work/chromedriver')

driver.get(my_url)

page_s = soup(driver.page_source, features='html.parser')

containers = page_s.select("div.home-name>p>a[href]")


for container in containers:

    print(container.text.strip())

輸出:


Silk Court

Westport Care Home

Aspen Court Care Home

Beaumont Court

Hawthorn Green Residential and Nursing Home

Coxley House

Toby Lodge

Hotel in the Park

34/35 Huddleston Close

Approach Lodge


查看完整回答
反對(duì) 回復(fù) 2023-10-24
?
慕姐8265434

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊

您可以嘗試以下解決方案嗎:


driver.get(" https://www.carehome.co.uk/care_search_results.cfm/searchunitary/Tower-Hamlets ")


containers=WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.XPATH,"//div[contains(@class,'home-name')]//p//a[@href]")))


for container in containers:

     print container.text

https://img1.sycdn.imooc.com/6537caa000019b7908890315.jpg

查看完整回答
反對(duì) 回復(fù) 2023-10-24
  • 2 回答
  • 0 關(guān)注
  • 184 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)