使用wordpress wpdb在数据库中插入表单数据

时间:2018-09-16 07:34:37

标签: wordpress

我正在用Wordpress表单创建一个新博客帖子插件已成功创建如何将表单数据存储在数据库中

register_activation_hook(__FILE__,'create_books_table');
register_deactivation_hook(__FILE__,'truncate_book_table');
add_action('init','book_assets');
add_action("admin_menu", "my_book_plugin_menus");

enter image description here

1 个答案:

答案 0 :(得分:1)

这里是如何使用$ wpdb将数据插入数据库的示例。

from bs4 import BeautifulSoup
import requests

url = 'https://en.wikipedia.org/wiki/List_of_Texas_Rangers_seasons'
r = requests.get(url)

soup = BeautifulSoup(r.text,'lxml')

#method 1
for row in soup.select('table.plainrowheaders tr')[14:]:
    for cell in row.select('td'):
        print(cell.text.strip(), end=' ')
    print()

#method 2
for row in soup.select('table.plainrowheaders tr')[14:]:
    print(row.get_text(strip=True, separator=' '))

访问https://codex.wordpress.org/Creating_Tables_with_Plugins了解更多信息。