小编Chr*_*ris的帖子

Python和sqlite3抛出错误:sqlite3.OperationalError:near"s":语法错误

我正在尝试使用Python和BeautifulSoup来抓取一些Web信息,迭代它然后将一些部分插入到sqlite3数据库中.但我不断提出这个错误:

文件"/Users/Chris/Desktop/BS4/TBTfile.py",第103行,TBTscrape c.execute(item)sqlite3.OperationalError:near"s":语法错误

相同的代码在非常相似的刮刀上工作正常,并且不会抛出这些错误.这是它的一部分:

listicle.append("INSERT INTO headlines (heds, url, image_loc, time, source) VALUES ('" + TBTheadline + "', '" + TBTurl + "', '" + imageName + "', '" + TBTpostDate + "', '" + source + "')")

    else:
        print "TBT item already in database"

print listicle

for item in listicle:
    c.execute(item)
    conn.commit()
    row = c.fetchall()
    print "This has been inserted succcessfully: ", item
Run Code Online (Sandbox Code Playgroud)

python sqlite web-scraping

2
推荐指数
1
解决办法
3486
查看次数

PHP MySQL在预准备语句中围绕匿名变量抛出错误

当我运行我准备好的语句时,我收到以下错误:

错误:INSERT INTO文章(url,headline,pubDate,source,image_loc(?????,,,,))VALUES您的SQL语法错误; 查看与您的MySQL服务器版本对应的手册,以便在第6行使用"?,?,?,?,?)"附近的正确语法

这是似乎抛出错误的代码:

            $sql = "INSERT INTO $tableName (`url`, 
                            `headline`, 
                            `pubDate`, 
                            `source`, 
                            `image_loc`) 
                VALUES(?, ?, ?, ?, ?)";

        // MySQLi connection, binds variables to prevent injection, executes
        $stmt = $connection->prepare($sql);
        $stmt->bind_param('sssss', $url, $headline, $pubDate, $source, $image_loc);
        $stmt->execute();
Run Code Online (Sandbox Code Playgroud)

编辑:这是我在单独的文件中设置为我的连接.它起作用的意义是一切都被保存了......我只是在抛出一个错误.

$servername = "localhost";
$username = "xxxxxx";
$password = "xxxxxx";
$dbname = "news";
$tableName = "articles";

$connection = mysqli_connect($servername, $username, $password, $dbname);

if (!$connection) {
  die("Connection failed: " . mysqli_connect_error());
} …
Run Code Online (Sandbox Code Playgroud)

php mysql prepared-statement

1
推荐指数
1
解决办法
67
查看次数

标签 统计

mysql ×1

php ×1

prepared-statement ×1

python ×1

sqlite ×1

web-scraping ×1