分布式爬虫(5):微博数据爬取

一、使用Selenium+Phantoms来抓取数据

    1.登录:最重要的是设置User-Agent,否则无法转跳链接 

from selenium.webdriver.common.desired_capability import DesiredCapabilities
user_agent=(
  "Mozilla/5.0()"

)

    2.输入用户名和密码:

<input id="loginname"
type="text"
class="W input" maxlength="128"
autocomplete="off"
action-data="text=........"
name="username"
node-type="username" 
tabindex="1">

    (1)为了与微博内容交互,需要用到javascript

      相关的javascript代码:

      document.getElementById('loginname').value='abc'

      document.getElementsByName('password')[0].value='abc'

      通过Selenium提供的send_keys来进行传递value

      driver.find_element_by_id('loginname').send_keys(username)

      driver.find_element_by_name('password').send_keys(password)

二、微博接口分析

三、直接调用微博API来抓取

四、表单及登录

四、表单及登录

猜你喜欢

转载自www.cnblogs.com/bigdata-stone/p/9861479.html