zoukankan      html  css  js  c++  java
  • 对书名的抓取

    import urllib as request
    import sys
    sys.path.append('E:/software/python/beautifulsoup4-4.5.3')    //---------这里要引在本地安装的的beautifulsoup4,其作用看本python类博客
    sys.path.append('E:/software/python/Lib/site-packages')      //---------这里要引在本地安装的的python的lib库
    from bs4 import BeautifulSoup
    import MySQLdb
    import re
    res = request.urlopen("http://www.douban.com/tag/%E5%B0%8F%E8%AF%B4/?focus=book")

    soup = BeautifulSoup(''.join(res.read()),'html.parser')
    #print soup
    book_div = soup.find(attrs={"id":"book"})
    book_a = book_div.findAll(attrs={"class":"title"})
    connection = MySQLdb.connect(host="localhost",user="root",passwd="123456",db="kunlun",port=3306,charset="utf8")
    cursor = connection.cursor()
    for book in book_a:
    print book.string
      sql ="INSERT INTO books(bookname) VALUES ('%s') " %(book.string)
      #sql ="INSERT INTO books(bookname)VALUES (%s)" %("'"+book.string+"'")
      sql_res = cursor.execute(sql)
    connection.commit()
    cursor.close()
    connection.close()

  • 相关阅读:
    第12组 Alpha冲刺(4/6)
    第12组 Alpha冲刺(3/6)
    第12组 Alpha冲刺(2/6)
    第12组 Alpha冲刺 (1/6)
    第12组(78) 需求分析报告
    第12组(78)团队展示
    结对编程作业
    第06组Beta冲刺(2/5)-(组长)
    第06组Beta冲刺(1/5)-(组长)
    第06组Alpha冲刺(6/6)-(组长)
  • 原文地址:https://www.cnblogs.com/kongxc/p/7782832.html
Copyright © 2011-2022 走看看