python爬虫案例12个_Python 爬虫实例(12)—— python selenium 爬虫

# coding:utf-8

from common.contest import *def spider():

url = "http://www.salamoyua.com/es/subasta.aspx?origen=subastas&subasta=79"

chromedriver = 'C:/Users/xuchunlin/AppData/Local/Google/Chrome/Application/chromedriver.exe'chome_options =webdriver.ChromeOptions()

#使用代理

# proxies = r.get('4')

# chome_options.add_argument(('--proxy-server=http://' +proxies))

os.environ["webdriver.chrome.driver"] =chromedriver

driver = webdriver.Chrome(chromedriver, chrome_options=chome_options)

for i in range(1,100):

print "正在爬取第" + str(i) + "页的数据"

if i ==1:

# 请求url

driver.get(session_url)

result =driver.page_source

else:

try:

# 将页面滚动条拖到底部

js = "var q=document.documentElement.scrollTop=10000"driver.execute_script(js)

driver.find_element_by_id('ctl00_phContenidos_lbSiguiente').click()

# 得到爬取页面的结果

result =driver.page_source

time.sleep(3)

except:

result = ""soup = BeautifulSoup(result, 'html.parser')

result_div = soup.find_all('figure', attrs={"class": "Lotes fade"})

# print len(result_div)

for i inresult_div:

result_replace = replace(i)

print result_replace

item_url = re.findall('

item_imgurl = re.findall('

if "Remate" not in result_replace:

sold_price = ""

else:

sold_price = re.findall('

Remate:(.*?)

', result_replace)[0]

sold_price = sold_price.replace(' ','')

try:

item_lotnum = re.findall('title="Lote vendido">(.*?)', result_replace)[0]

item_lotnum = item_lotnum.replace('Lote','').replace(' ','')

except:

item_lotnum = re.findall('(.*?)',result_replace)[0]

item_lotnum = item_lotnum.replace('Lote', '').replace(' ', '')

print item_url

print item_lotnum

print item_imgurl

print sold_price

spider()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值