我用Python脚本制作了一个硒,可以扫描Instagram ID的追随者,并且在本地完美运行。但是当我尝试在服务器上运行它不起作用
我尝试了chrome和Firefox驱动程序都在本地工作,但不能在服务器上工作。下面的代码是在加载用户ID之后的代码。在加载用户ID之前可以正常工作。
arrow = driver.find_element_by_xpath('//a[@class="-nal3 "]')
arrow.click()
follower = []
for i in tqdm(range(4), desc='scrolling for follower'):
driver.save_screenshot('scrollingfollowers.png')
if driver.find_elements_by_css_selector('h1.m82CD'):
arrow1 = driver.find_element_by_class_name('isgrP')
arrow1 = driver.find_element_by_tag_name("body")
arrow1.click()
time.sleep(0.2)
arrow1.send_keys(Keys.SPACE)
else:
driver.back()
arrow1 = driver.find_element_by_class_name('isgrP')
arrow1 = driver.find_element_by_tag_name("body")
arrow1.click()
time.sleep(0.2)
arrow1.send_keys(Keys.END)
html_source = driver.page_source
source_data = html_source.encode('utf-8')
soup = bs(source_data, 'lxml')
for div in soup.findAll('a', {'class': 'FPmhX notranslate _0imsa '}):
if div.text not in follower:
follower.append(div.text)
已解决
谢谢您的答复,但我知道了。问题是我正在用漂亮的汤来获得追随者的所有信息。它在本地工作,但是当我在服务器上运行它时,并没有收集该数据。 我使用硒本身来获取关注者的数据
for i in tqdm(range(4),desc='scrolling for follower'):
time.sleep(1)
followersList = driver.find_element_by_css_selector('div[role=\'dialog\'] ul')
numberOfFollowersInList = len(followersList.find_elements_by_css_selector('li'))
if int(numberOfFollowersInList) > tenpercent:
break
followersList.click()
actionChain.key_down(Keys.SPACE).perform()
for user in followersList.find_elements_by_css_selector('li'):
userLink = user.find_element_by_css_selector('a').get_attribute('href')
getuser = userLink.split('/')
print(getuser[3])
follower.append(getuser[3])