106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/bin/env python
#coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
import urllib
import urllib2
import sys
import os
import re
import csv
import numpy as np
# 解决中文报错的问题
reload(sys)
sys.setdefaultencoding('utf-8')
csvfile = file('data.csv', 'wb')
writer = csv.writer(csvfile)
writer.writerow((u'企业名称'.encode('gbk'), u'主页'.encode('gbk'), u'产品'.encode('gbk')
, u'联系人'.encode('gbk'), u'电话'.encode('gbk'), u'地址'.encode('gbk')))
url = '
635.1998096057.d1'
loginUrl = '
full_redirect=trueredirect_url=
_is_blank_1688%26tracelog%3Dmember_signout_signin_s_reg'
driver = webdriver.Firefox()
time.sleep(3)
driver.get(loginUrl)
time.sleep(5)
driver.find_element_by_name("TPL_username").send_keys('这里输入你的淘宝账号')
driver.find_element_by_name("TPL_password").send_keys('这里输入你的淘宝密码')
driver.find_element_by_name("TPL_password").send_keys(Keys.ENTER)
time.sleep(5)
driver.get(url)
time.sleep(15)
user_agents = [
'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.
0.0.11',
'Opera/9.25 (Windows NT 5.1; U; en)',
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR
2.0.50727)',
'Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Kubuntu)',
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-se
curity Firefox/1.5.0.12',
'Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9',
"Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Ubuntu/11.04 Chr
omium/16.0.912.77 Chrome/16.0.912.77 Safari/535.7",
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0 ",
]
for page in xrange(1, 100):
try:
title = driver.find_elements_by_css_selector("a[class=list-item-title-text]")
product = driver.find_elements_by_xpath("//div[@class=\"list-item-detail\"]/div[1]
/div[1]/a[1]")
print len(title)
pattern = re.compile('div class="contcat-desc".*?(.*?)/div', re.S)
telPattern = re.compile('dd(.*?)/dd', re.S)
membernamePattern = re.compile('a.*?class="membername".*?(.*?)/a', re.S)
addressPattern = re.compile('"address"(.*?)/dd', re.S)
for i in xrange(len(title)):
titleValue = https://www.04ip.com/post/title[i].get_attribute('title')
hrefValue = https://www.04ip.com/post/title[i].get_attribute('href') + 'page/contactinfo.htm'
productValue = https://www.04ip.com/post/product[i].text
agent = np.random.choice(user_agents)
headers = {'User-Agent' : agent, 'Accept' : '*/*', 'Referer' : ''}
request = urllib2.Request(hrefValue, headers=headers)
response = urllib2.urlopen(request)
html = response.read()
info = re.findall(pattern, html)
try:
info = info[0]
except Exception, e:
continue
tel = re.findall(telPattern, info)
try:
tel = tel[0]
tel = tel.strip()
tel = tel.replace(' ', '-')
except Exception, e:
continue
membername = re.findall(membernamePattern, html)
try:
membername = membername[0]
membername = membername.strip()
except Exception, e:
continue
address = re.findall(addressPattern, html)
try:
address = address[0]
推荐阅读
- 区块链合作,区块链交易所开发
- js中dataoptions的简单介绍
- sap销售订单删除,sap销售订单删除怎么删
- 网络游戏有关数据,有关游戏的数据
- php打印行数据 php打印对象
- flutter无法启动模拟器,Flutter启动白屏
- 关于linux命令scp的信息
- go语言大厂意思 go语言用的多吗
- 怎么用小程序开车门锁视频,怎么用小程序开车门锁视频教学