[英]Pull profile name from LinkedIn URL in Python
I'm trying to pull the profile name from the following URL: https://www.linkedin.com/in/zamenajaffer/我正在尝试从以下 URL 中提取配置文件名称: https://www.linkedin.com/in/zamenajaffer/
Ideally, I want to extract the "zamenajaffer" from the URL and convert it to string.理想情况下,我想从 URL 中提取“zamenajaffer”并将其转换为字符串。
Here is what I have so far:这是我到目前为止所拥有的:
#importing packages for web scraping
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
import re
import time
### Opening LinkedIn Account ###
#request user input for LinkedIn credentials
print("Please enter your email address: ")
username_string = str(input())
print("Please enter your password: ")
password_string = str(input())
#create browser-specific web navigation simulator (chrome)
browser = webdriver.Chrome(executable_path= '/Applications/Python 3.8/chromedriver')
#open LinkedIn and log in with given details
browser.get('https://www.linkedin.com/login')
elementID = browser.find_element_by_id('username')
elementID.send_keys(username_string)
elementID = browser.find_element_by_id('password')
elementID.send_keys(password_string)
elementID.submit()
#navigate to recent activity page
browser.get('https://www.linkedin.com/in/')
print(browser.current_url)
It currently prints https://www.linkedin.com/in/
.它目前打印
https://www.linkedin.com/in/
。 What I want it to print is https://www.linkedin.com/in/zamenajaffer/
, as is shown in the browser when the code runs:我希望它打印的是
https://www.linkedin.com/in/zamenajaffer/
,代码运行时在浏览器中显示:
You have to add delay while page is loaded and only after that to print(browser.current_url)
您必须在页面加载时添加延迟,然后才能
print(browser.current_url)
So you can add所以你可以添加
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 30)
element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'live-video-hero-image')))
And then接着
print(browser.current_url)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.