各种获取信息

商品信息

using Ivony.Html.Parser;
using Ivony.Html;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Skay.WebBot;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Data.SqlClient;

namespace taobao
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static Thread th;
        private void button1_Click(object sender, EventArgs e)
        {
            th = new Thread(new ThreadStart(JDData));
            th.Start();
        }
        void JDData()
        {
            for(int i = 1; i <= 10; i++)
            {
                string str = "http://list.jd.com/list.html?cat=9987,653,655&page="+i+"&ext=502864::1943^^&go=0&JL=6_0_0";
                HttpUtility httpOne = new HttpUtility();
                string htmlOne = httpOne.GetHtmlText(str);
                var documenthtml = new JumonyParser().Parse(htmlOne);
                var items = documenthtml.Find(".gl-item");
                foreach(var item in items)
                {
                    string title = item.FindFirst(".p-name em").InnerText(); //商品名称
                    string contents = item.FindFirst(".p-commit strong a").InnerText();//评论人数
                    string vender = item.FindFirst(".p-shop").Attribute("data-shop_name").Value();//卖主
                    //string vender = item.FindFirst(".p-shop span a").InnerText();
                    string surl = item.FindFirst(".p-name a").Attribute("href").Value();

                    HttpUtility httpsurl = new HttpUtility();
                    string htmlsurl = httpsurl.GetHtmlText(surl, "gbk", "text/html; charset=gbk");
                    string screen, resolution_ratio, camer_fore, camer_back;
                    screen = resolution_ratio = camer_fore = camer_back = "";
                    var documenthtmlsurl = new JumonyParser().Parse(htmlsurl);
                    try
                    {
                         screen = documenthtmlsurl.FindFirst(".detail p").InnerText().Split(‘:‘)[1];//屏幕大小
                         resolution_ratio = documenthtmlsurl.FindLast(".fore0 .detail p").InnerText().Split(‘:‘)[1];//分辨率
                         camer_fore = documenthtmlsurl.FindFirst(".fore1 .detail p").Attribute("title").Value();//前摄像头
                         camer_back = documenthtmlsurl.FindLast(".fore1 .detail p").Attribute("title").Value();//后摄像头
                    }
                    catch
                    {

                    }
                    string AllCots, imgCots, GoodCots, MidCots, lowCots;
                    string weight, Nametitle, goodsId = "", onselfTime, From1, hotPoint, system1, color, priceEnd="";
                    AllCots = imgCots = GoodCots = MidCots = lowCots = weight = Nametitle = goodsId = onselfTime = From1 = hotPoint = system1 = color = "";
                    var things = documenthtmlsurl.Find("#parameter2 li");
                    foreach(var thing in things)
                    {
                        try
                        {
                            if (thing.InnerText().Split(‘:‘)[0].Trim() == "商品毛重")
                            {
                                weight = thing.InnerText().Split(‘:‘)[1];
                            }
                            else if (thing.InnerText().Split(‘:‘)[0].Trim() == "商品名称")
                            {
                                Nametitle = thing.InnerText().Split(‘:‘)[1];
                            }
                            else if (thing.InnerText().Split(‘:‘)[0].Trim() == "商品编号")
                            {
                                goodsId = thing.InnerText().Split(‘:‘)[1];
                            }
                            else if (thing.InnerText().Split(‘:‘)[0].Trim() == "上架时间")
                            {
                                onselfTime = thing.InnerText().Split(‘:‘)[1];
                            }
                            else if (thing.InnerText().Split(‘:‘)[0].Trim() == "商品产地")
                            {
                                From1 = thing.InnerText().Split(‘:‘)[1];
                            }
                            else if (thing.InnerText().Split(‘:‘)[0].Trim() == "热点")
                            {
                                hotPoint = thing.InnerText().Split(‘:‘)[1];
                            }
                            else if (thing.InnerText().Split(‘:‘)[0].Trim() == "系统")
                            {
                                system1 = thing.InnerText().Split(‘:‘)[1];
                            }
                            else if (thing.InnerText().Split(‘:‘)[0].Trim() == "机身颜色")
                            {
                                color = thing.InnerText().Split(‘:‘)[1];
                            }
                        }
                        catch { }
                    }
                    string priceUrl = "http://p.3.cn/prices/get?type=1&area=1_72_4137&pdtk=&pduid=795687743&pdpin=&pdbp=0&skuid=J_"+goodsId+"&callback=cnp";
                    string subhtml = httpsurl.GetHtmlText(surl, "gbk", "text/html; charset=gbk");
                    string Area_html = httpsurl.GetHtmlText(priceUrl, "gbk", "text/html;charset=gbk", "");

                    try
                    {
                        //JObject Area_Jo = (JObject)JsonConvert.DeserializeObject(Area_html);
                        JObject Area_Jo = (JObject)JsonConvert.DeserializeObject(Area_html.Replace("cnp", "").Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "").Replace(";", ""));
                        priceEnd = Area_Jo["p"].ToString();//价格
                    }
                    catch
                    {
                        MessageBox.Show("捕获异常");
                    }

                    //string urlEnd = "http://club.jd.com/productpage/p-"+goodsId+"-s-0-t-5-p-0.html?callback=fetchJSON_comment98vv22256";
                    string urlEnd = "http://club.jd.com/clubservice.aspx?method=GetCommentsCount&referenceIds="+goodsId;
                    string subhtmlEnd = httpsurl.GetHtmlText(urlEnd, "gbk", "text/html; charset=gbk");
                    string Area_htmlEnd = httpsurl.GetHtmlText(urlEnd, "gbk", "text/html;charset=gbk", "");
                    try
                    {
                        string sad = "500";
                        JObject Area_Jo = (JObject)JsonConvert.DeserializeObject(Area_htmlEnd.Split(‘[‘)[1].Replace("]}", ""));
                        AllCots = Area_Jo["CommentCount"].ToString();
                        imgCots = sad;
                        GoodCots = Area_Jo["GoodCount"].ToString();
                        MidCots = Area_Jo["GeneralCount"].ToString();
                        lowCots = Area_Jo["PoorCount"].ToString();
                    }
                    catch
                    {
                        MessageBox.Show("异常");
                    }

                    SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=StuTinafirst;User ID=sa;Password=123456");
                    conn.Open();
                    string into = string.Format("insert into jdfirst (name, contents, vender, screen, resolution_ratio, camer_fore, camer_back, AllCots, imgCots, GoodCots, MidCots, lowCots, weight, Nametitle, goodsId, onselfTime, From1, hotPoint, system1, color, priceEnd) values (‘"+title+"‘, ‘"+contents+"‘,‘"+vender+"‘,‘"+screen+"‘,‘"+resolution_ratio+"‘,‘"+camer_fore+"‘,‘"+camer_back+"‘,‘"+AllCots+"‘, ‘"+imgCots+"‘, ‘"+GoodCots+"‘, ‘"+MidCots+"‘, ‘"+lowCots+"‘, ‘"+weight+"‘, ‘"+Nametitle+"‘, ‘"+goodsId+"‘, ‘"+onselfTime+"‘, ‘"+From1+"‘, ‘"+hotPoint+"‘, ‘"+system1+"‘, ‘"+color+"‘, ‘"+priceEnd+"‘)");
                    SqlCommand com = new SqlCommand(into, conn);
                    int s = com.ExecuteNonQuery();
                }
            }
        }
    }
}

  

时间: 2024-10-17 07:47:01

各种获取信息的相关文章

[源码下载]Demo1 客户端从服务器获取信息(基于networkcomms2.3.1)

本demo基于networkcomms2.3.1开源版本 源码下载:从服务器获取信息   框架部分源码请到这里下载 实现的功能很简单 1:服务器开始监听 2:客户端连接服务器 并从服务器获取信息 源码在后续文章中

调用ZoomEye API获取信息

最近在提高自己编程能力,拿一些实用的小工具练下.该脚本为python语言,主要涉及模块urllib,json,os模块. 功能:调用ZoomEye API获取信息 import urllib.request import json import os def login(): username = input("username:") password = input("password:") url = "https://api.zoomeye.org/

跟王老师学反射(四):Class类:从Class类中获取信息

跟王老师学反射(四)Class类:从Class类中获取信息 主讲教师:王少华   QQ群号:483773664 学习内容 获得class类中的信息 根据我们以前学过的一个Java类有以下几部组成,如下代码所示 一.访问Class对应的类所包含的构造方法 (一)public Constructor<T> getConstructor(Class<?>... parameterTypes) 返回此Class对象所表示的类的指定public构造方法. parameterTypes参数是按

HR开发 获取信息类型数据

1.PNP逻辑数据库. LOOP获取信息类型数据. TABLES: PERNR . INFOTYPES: 0000, 0001 . START-OF-SELECTION. GET PERNR . LOOP AT P0000 WHERE ... ... ENDLOOP. LOOP AT P0001 WHERE ... ... ENDLOOP. 宏获取信息类型数据. TABLES: PERNR, T001P. INFOTYPES: 0000, 0001 . GET PERNR . RP_PROVID

使用SharedPreferences保存和获取信息

//保存信息 SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);  //Context.MODE_PRIVATE 私有类型 Editor editor = sp.edit(); //保存数据 editor.putString("username", username); editor.putString("password", p

c#从Web Service 获取信息并解析json

如果需要登录,使用下边方法,如果为匿名登录的,可以省略,在全局变量中定义public static string Cookiemsg,方便重复使用cookie. 1 public static CookieMsg GetCookieMessage(string name, string password) 2 { 3 CookieMsg cookieMsg = null; 4 string retString = ""; 5 try 6 { 7 HttpWebRequest reque

电影控、如何从视频文件名获取信息

喜欢看电影的你想必对 1080P.AAC.x264 这些字眼不陌生,那他们究竟包含着什么信息,下面我来“深度”解剖一下. 先来讲讲 360P.480P.720P.1080P 这些 P 看到这了,身居屏幕前的宅男们会说了,我只知道 3P.还有 1080P? 其实啊,这里的 P 意为逐行扫描(Progressive scan),720P 即 720 线逐行扫描,1080P 即 1080 线逐行扫描,数字越大,分辨率越高. 看到下组数据,你就明白了.(注意下划线部分) 480P格式,分辨率为720x4

SharedPreferences存储获取信息例子

SharedPreferences的使用非常简单,能够轻松的存放数据和读取数据.SharedPreferences只能保存简单类型的数据,例如,String.int等.一般会将复杂类型的数据转换成Base64编码,然后将转换后的数据以字符串的形式保存在 XML文件中,再用SharedPreferences保存. 使用SharedPreferences保存key-value对的步骤如下: (1)使用Activity类的getSharedPreferences方法获得SharedPreference

背水一战 Windows 10 (122) - 其它: 通过 Windows.System.Profile 命名空间下的类获取信息, 查找指定类或接口的所在程序集的所有子类和子接口

[源码下载] 作者:webabcd 介绍背水一战 Windows 10 之 其它 通过 Windows.System.Profile 命名空间下的类获取信息 查找指定类或接口的所在程序集的所有子类和子接口 示例1.演示如何通过 Windows.System.Profile 命名空间下的类获取信息Information/ProfileInfo.xaml <Page x:Class="Windows10.Information.ProfileInfo" xmlns="htt

微信小程序--通过请求网页获取信息并显示

效果描述: 按动主页按钮跳转至列表页,在列表页显示请求网页所获取的信息,并通过所得信息的id的不同,链接到不同的网页进一步获取不同信息. 触碰按钮跳转至列表页触碰表题按钮跳转至详情页,其中不同的按钮对应的详情页内容不同而格式相同. 这样的好处是,可以通过网页信息的改变自动改变页面信息. 流程: 使用Api: wx.request() //请求网页信息wx.navigateTo()  //跳转页面 注意点: 1.在列表页,要将网页上获取的信息根据id的不同,选择对应信息显示在列表页,并将其显示在详