我正在嘗試從使用 Selenium 的頁面獲取鏈接。檢查頁面源代碼時,我可以清楚地看到原始鏈接,但是當我使用 Selenium 選擇元素,然后使用 element.get_attribute('href') 時,它回傳的鏈接是不同的。
# Web page url request
driver.get('https://www.facebook.com/ads/library/?active_status=all&ad_type=all&country=BR&q=myshopify&sort_data[direction]=desc&sort_data[mode]=relevancy_monthly_grouped&search_type=keyword_unordered&media_type=all')
driver.maximize_window()
time.sleep(10)
v_link = driver.find_element(By.XPATH, '//*[@id="facebook"]/body/div[5]/div[2]/div/div/div/div/div[3]/span/div[1]/div/div[2]/div[1]/div[2]/div[3]/a')
print(v_link.get_attribute('href'))
我需要的實際鏈接:https ://bhalliproducts.store/?_pos=1&_sid=8a26757f5&_ss=r
回傳的鏈接:https://l.facebook.com/l.php?u=https://bhalliproducts.store/?_pos=1&_sid=8a26757f5&_ss=r&h=AT3KkXQbOn5s3oaaaCV2vjaAnyJqEqkIlqvP16g3eCsCnw-fx3VCNMR66_Zxs50v9JU5JK2DLABhoBHRNHQENH6oyp39Pho2Z6o25NZD5RIvl5kMow0lfd2rdaUWp11e6alEJFtoJp0X_uXgp5B2OYocRg5wGA
uj5u.com熱心網友回復:
您可以使用以下解決方案:
from urllib.parse import unquote
href = "https://l.facebook.com/l.php?u=https://bhalliproducts.store/?_pos=1&_sid=8a26757f5&_ss=r&h=AT3KkXQbOn5s3oaaaCV2vjaAnyJqEqkIlqvP16g3eCsCnw-fx3VCNMR66_Zxs50v9JU5JK2DLABhoBHRNHQENH6oyp39Pho2Z6o25NZD5RIvl5kMow0lfd2rdaUWp11e6alEJFtoJp0X_uXgp5B2OYocRg5wGA"
begin = href.find('=') 1
end = href.find('&')
href = href[begin:end]
href = unquote(href)
print(href)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/449457.html
上一篇:用水豚填充文本框
下一篇:我需要使用python從html中獲取文本,但是在html中有2個具有相同類名的元素,我需要同時獲取這兩個元素并放入一個陣列
