专栏中心

EEPW首页 > 专栏 > 实现爬虫的思路

实现爬虫的思路

发布人:laical 时间:2020-09-15 来源:工程师 发布文章

网络爬虫通过程序模拟浏览器请求站点的行为,把网站返回的数据爬到本地,提取自己需要的数据,存储起来使用。

爬虫构成

1、确定目标网站

2、解析目标网站的数据信息

3、程序模拟用户发出http请求获取数据

4、从获取的数据中保存到本地,删选需要的相关数据

5、对获取到的数据根据自己的需求使用

imbkrmdb2m.png

注意

一般做爬虫都会加上请求头

User-agent:请求头中如果没有user-agent,目标网站可能将你当做一个非法用户

cookies:cookie用来保存登录信息

爬虫实践

以下是关于网络爬虫采集数据的实践操作,通过爬虫程序模拟用户分析网站采集数据解析数据保存数据。代码仅供参考:

import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider;
import com.gargoylesoftware.htmlunit.WebClient;

public class FirefoxDriverProxyDemo
{
    // 代理隧道验证信息
    final static String proxyUser = "username";
    final static String proxyPass = "password";

    // 代理服务器
    final static String proxyHost = "t.16yun.cn";
    final static int proxyPort = 31111;

    final static String firefoxBin = "C:/Program Files/Mozilla Firefox/firefox.exe";

    public static void main(String[] args) throws JSONException
    {
        System.setProperty("webdriver.firefox.bin", firefoxBin);

        FirefoxProfile profile = new FirefoxProfile();

        profile.setPreference("network.proxy.type", 1);


        profile.setPreference("network.proxy.http", proxyHost);
        profile.setPreference("network.proxy.http_port", proxyPort);

        profile.setPreference("network.proxy.ssl", proxyHost);
        profile.setPreference("network.proxy.ssl_port", proxyPort);

        profile.setPreference("username", proxyUser);
        profile.setPreference("password", proxyPass);


        profile.setPreference("network.proxy.share_proxy_settings", true);


        profile.setPreference("network.proxy.no_proxies_on", "localhost");


        FirefoxDriver driver = new FirefoxDriver(profile);
    }
}


专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们

关键词:

相关推荐

Oversonic Robotics 签署与意法半导体合作的人形机器人供应协议

第三季度数据中心资本支出同比增长59%

ASML芯片制造的极紫外光刻机在生物医学领域令人惊讶——它们能够批量生产用于分子传感的纳米孔

航空维护中的人工智能与机器人技术:提升MRO的变革

该阀门可将电动车快充时间缩短一半:分区散热技术保持电池温度较低,加快充电速度

2026年初TI、ADI带头涨价 台系模拟IC设计看法两极

模拟技术 2025-12-23

国图手机移动图书馆案例分析 中

视频 2009-11-02

人工智能模型在一个简单的任务上表现惨败:计时

Symbian OS多媒体架构分析 上

视频 2009-11-02

亚马逊将重组由AWS资深高管领导的AI团队

智能计算 2025-12-23

pr

c枋wonvv 2005-10-12

Symbian OS多媒体架构分析 下

视频 2009-11-02

Symbian C++开发入门之概述 上

视频 2009-11-02

事实证明,人工智能实际上能制造出称职的扫雷克隆——四个AI编码代理的测试显示OpenAI的Codex是最好的,而谷歌的Gemini CLI是最差的

SiC市场发展周期修正

电源与新能源 2025-12-23

国图手机移动图书馆案例分析 下

视频 2009-11-02
更多 培训课堂
更多 焦点
更多 视频

技术专区