分享Python7个爬虫小案例(附源码)
凉C冰:
把链接地址中的尖括号去除,另外替换内容[code=python]
price = book.xpath('p[@class="price"]/span[@class="search_now_price"]/text()')
if len(price) == 0:
price = "暂无"
else:
price = price[0];
author = book.xpath('p[@class="search_book_author"]/span[1]/a/@title')
if len(author) == 0:
author = "暂无"
else:
author = author[0];
publish_date = book.xpath('p[@class="search_book_author"]/span[2]/text()')
if len(publish_date) == 0:
publish_date = "暂无"
else:
publish_date = publish_date[0];
publisher = book.xpath('p[@class="search_book_author"]/span[3]/a/@title')
if len(publisher) == 0:
publisher = "暂无"
else:
publisher = publisher[0];
[/code]
|