【发布时间】:2019-05-26 04:02:03
【问题描述】:
我检查了登录是 200 作为响应,但结果什么也没打印。 这是代码:
import requests
from bs4 import BeautifulSoup
file_in = 'D:\OneDrive\Documents\GPIP\Files\scraping\idlinkedin.csv'
dataset = open(file_in, "r")
def login(iemail,ipassword):
client = requests.Session()
HOMEPAGE_URL = 'https://www.linkedin.com'
LOGIN_URL = 'https://www.linkedin.com/uas/login-submit'
html = client.get(HOMEPAGE_URL).content
soup = BeautifulSoup(html, "html.parser")
csrf = soup.find(id="loginCsrfParam-login")['value']
login_information = {
'session_key': iemail,
'session_password': ipassword,
'loginCsrfParam': csrf,
}
client.post(LOGIN_URL, data=login_information)
for username in dataset:
item_url = 'https://www.linkedin.com/in/' + username.strip()
source_code = client.get(item_url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, features='html.parser')
for item_name in soup.findAll('h1', {'class': 'pv-top-card-section__name inline t-24 t-black t-normal'}):
print(item_name)
# MAIN
login('theusername','thepassword')
这行应该是打印姓名的账号,可惜结果什么都没有。
for item_name in soup.findAll('h1', {'class': 'pv-top-card-section__name inline t-24 t-black t-normal'}):
print(item_name)
【问题讨论】:
-
你能把你在
plain_text得到的内容贴出来吗? -
你可以尝试使用 lxml 解析器并使用 find_all 函数吗?这可能会奏效。而且我从未使用过 findAll 函数,请在 git hub 上参考我的代码一次。 github.com/simplyshravan/python_learning/blob/master/Freelancer/…
标签: python web-scraping beautifulsoup