标题和价格的爬取,主要是遍历的方法


import re
import urllib2

def get_html():
html = urllib2.urlopen("http://uland.taobao.com/sem/tbsearch").read()
r = r'target="_blank">&yen; <strong>(.*)</strong>'
reg = re.compile(r)
text = re.findall(reg,html)
return text

def get_html1():
html = urllib2.urlopen("http://uland.taobao.com/sem/tbsearch").read()
r = r' target="_blank" class="title" title="(.*)">(.*)</a>'
reg = re.compile(r)
text = re.findall(reg,html)
return text

dict = {}
price = get_html()
title = get_html1()
list = []
for k in title:
list.append(k[-1])

for i in range(len(price)):
for j in range(len(list)):
if i==j:
dict[price[i]]=list[j]
fd=open('aaa.txt','a')
for k,v in dict.items():
fd.write(k+'\t'+v+'\n\n')
fd.close()


# - *- coding:utf-8 -*-
import urllib2
import re

def geturl():
html=urllib2.urlopen("http://uland.taobao.com/sem/tbsearch").read()
reg=re.compile(r' target="_blank" class="title" title="(.*?)">.*?</a>')
title=re.findall(reg,html)
return title
def geturl1():
html=urllib2.urlopen("http://uland.taobao.com/sem/tbsearch").read()
reg=re.compile(r' <strong>(.*?)</strong>')
title1=re.findall(reg,html)
return title1
fd=open('baobiao.txt','wb')
for(i,j) in zip(geturl(),geturl1()):

fd.write(i+'\t'+ j + '\r\n')
fd.close()

转载于:https://www.cnblogs.com/ZHANG576433951/p/6090038.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值