当您从一个网站接收数据时,如果您可以在登录后看到这些数据,您如何访问它?
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome('c://chromedriver.exe')
driver.get("http://www.gevolution.co.kr/rank/history.asp")
soup = BeautifulSoup(driver.page_source, 'html.parser')
blocks = soup.findAll('div', {'class': 'grp'})
bodys = []
for block in blocks:
body = block.text
body = str(body).strip()
bodys.append(body)
print(bodys)结果:[]
在我想收集的网站上收集数据的一些代码。顺便说一下,如果我自动打开Chrome,由于登录问题,它将不会被收集。我想知道如何解决登录问题。
发布于 2018-09-27 07:53:48
解决方案1
您可以使用locate the cookies,并使用该cookie启动selenium驱动程序。这不会永久解决问题,因为cookie将在一段时间后过期。
解决方案2
您可以通过模拟登录行为登录到网站。您可以使用selenium来模拟element.click()、element.send_keys('value')和selenium提供的许多其他神奇方法输入密码和用户名。
如果网站需要captchas登录,这将变得很困难。在这种情况下,您可以手动输入captcha,或者使用算法来识别它,或者使用解决方案1。
https://stackoverflow.com/questions/52531426
复制相似问题