1
Iamdoudou OP 求教,正在慢慢摸索中
|
2
CharlieTian 2018-01-05 16:08:36 +08:00
```
def process_contenturl(url,picture,price,desc):#处理具体商品链接内容 a=requests.get(url) change=etree.HTML(a.content) l=change.xpath('//div[@id="attributes"]/ul/li/text()') stock=change.xpath('//*[@id="J_SpanStock"]/text()')#获取商品库存 for i in range(len(l)): l[i]=l[i].replace(u'\xa0', '') if u"上市年份季节" in l[i]: saleseason=(l[i])[7:]#上市年份季节 elif u"材质成分" in l[i] : material=(l[i])[5:]#材质成分 elif u"货号" in l[i]: id=(l[i])[3:]#货号 elif u"适用性别" in l[i]: gender=(l[i])[5:]#适用性别 else: remarks="".join(l)#无关紧要的备注 sql="INSERT INTO UNIQLO(id,price,stock,salseason,material,gender,remarks,picture,desc) VALUE (%s,%s,%s,%s,%s,%s,%s,%s,%s)"%(id,price,stock,material,gender,remarks,picture,desc) print sql ``` 想想 id 什么时候才会被定义 |
3
fml87 2018-01-05 16:17:27 +08:00
这种情况,pycharm 会警告 local variable ‘ id ’ might be referebced before assigment 吧
|
4
Iamdoudou OP 这个我想了下,在前面定义了一个空的 id,但是现在做着发现了有一个错误,提示‘ gbk ’ codec cna't encode character u'\xa0'in position 421:illegal multibyte sequence
这块,我已经在循环里面增加了 for i in range(len(l)): l[i]=l[i].replace(u'\xa0', '') 为啥还是出现这个 |
5
VYSE 2018-01-05 16:33:56 +08:00
一猜就是这个新手会遇到的坑
def func(): a = 0 def run(): print a #a = 1 run() func() 把 a=1 开启注释就会报你那个异常 |
6
julyclyde 2018-01-05 20:44:07 +08:00
貌似 python2 特有?
|