我正在尝试构建一个机器人来发送linkedin中的请求。但运行此代码后,它一直工作到42行,然后停止。我怎样才能找出错误呢?有一个包含用户和密码的config.txt文件。为了安全起见,我不提供此文件。在这方面有人能帮我吗
import os, random, sys, time
from selenium import webdriver
from bs4 import BeautifulSoup
browser = webdriver.Chrome('C:\Program Files (x86)\chromedriver.exe')
browser.get('https://www.linkedin.com/uas/login?trk=hb_signin')
file = open('config.txt')
lines = file.readlines()
username = lines[0]
passwd = lines[1]
elementID = browser.find_element_by_id('username')
elementID.send_keys(username)
elementID = browser.find_element_by_id('password')
elementID.send_keys(passwd)
elementID.submit()
myID = '/in/kafee-khan-097a5b129/'
fulllink = 'https://www.linkedin.com/' + myID
browser.get(fulllink)
visitedProfiles = []
profileQueued = []
def getNewProfileIDs(soup,profileQueued):
profilesID = []
pav = soup.find('div',{'class':'pv-browsemap-section'})
all_links = pav.findAll('a',{'class':'pv-browsemap-section__member ember-view'})
for link in all_links:
userID = link.get('href')
if((userID not in visitedProfiles) and (userID not in profileQueued)):
profilesID.append(userID)
return profilesID
soup = BeautifulSoup(browser.page_source, "html.parser")
getNewProfileIDs(soup, profileQueued)
while profileQueued:
try:
visitedID = profileQueued.pop()
visitedProfiles.append(visitedID)
fullLink = "hhttps://www.linkedin.com" + visitedID
browser.get(fullLink)
browser.find_element_by_class_name('pv-s-profile-actions pv-s-profile-actions--connect ml2 artdeco-button artdeco-button--2 artdeco-button--primary ember-view').click()
browser.find_element_by_class_name('mr1').click()
message = "Hello, I am Muktadir. I like to connect with you."
elementID = browser.find_element_by_id('custom-message')
elementID.send_keys(message)
browser.find_element_by_class_name('artdeco-modal__dismiss').click()
soup = BeautifulSoup(browser.page_source, "html.parser")
try:
profileQueued.extend(getNewProfileIDs(soup, profileQueued))
except:
print('Continue')
except:
print('error')
debugging
软件开发实践,您可以在其中了解代码发生了什么。 如果您使用的是vs代码here is how you debug.Vs代码是一个很好的代码编辑器,有很多插件可以将其转换为IDE
但还有其他选择,比如PyCharm
相关问题 更多 >
编程相关推荐