首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在MySQL中查找包含任意数量的双引号和单引号的文本

如何在MySQL中查找包含任意数量的双引号和单引号的文本
EN

Stack Overflow用户
提问于 2021-07-29 14:55:41
回答 2查看 45关注 0票数 0

我正在抓取一个网站,它返回包含单引号和双引号的html,一个示例文本是

代码语言:javascript
复制
<div class="article__content">                                    <font face="Arial Helvetica sans-serif" size="3">Successful hires will expand the group's ongoing efforts applying machine learning to drug discovery biomolecular simulation and biophysics.  Ideal candidates will have demonstrated expertise in developing deep learning techniques as well as strong Python programming skills.  Relevant areas of experience might include molecular dynamics structural biology medicinal chemistry cheminformatics and/or quantum chemistry but specific knowledge of any of these areas is less critical than intellectual curiosity versatility and a track record of achievement and innovation in the field of machine learning.</font>                                </div>

当我在phpmyadmin中编写以下查询时:

代码语言:javascript
复制
SELECT COUNT(*) FROM scrappedjobs WHERE JobDescription = '"<div class="article__content">                                    <font face="Arial Helvetica sans-serif" size="3">Successful hires will expand the group's ongoing efforts applying machine learning to drug discovery biomolecular simulation and biophysics.  Ideal candidates will have demonstrated expertise in developing deep learning techniques as well as strong Python programming skills.  Relevant areas of experience might include molecular dynamics structural biology medicinal chemistry cheminformatics and/or quantum chemistry but specific knowledge of any of these areas is less critical than intellectual curiosity versatility and a track record of achievement and innovation in the field of machine learning.</font>                                </div>"'

当它存在于数据库中时,我得到错误或计数=0。请告诉我如何处理抓取的数据中包含引号的字符串。我是个新手,我找到的关于它的所有答案都是针对php的,而不是python。

编辑:

python is代码如下:

代码语言:javascript
复制
self.Cursor = self.db.cursor(buffered=True)
    FetchQuery = "SELECT COUNT(*) FROM scrappedjobs where URL = %s AND JobDescription = %s"
    self.Cursor.execute(FetchQuery,("\'" + item['url'] + "\'", item['text']))

    if(self.Cursor.fetchone()[0]== 0): #If the url does not exist in database
        print("Inserting into db...\n")
        InsertQuery = "INSERT INTO scrappedjobs (URL, JobTitle, JobDescription, CompanyName) VALUES (%s, %s, %s, %s)"
        self.Cursor.execute(InsertQuery,(item['url'], item['title'], item['text'], item['companyName']))
        self.db.commit()

基本上,if条件不会触发,尽管数据在数据库中。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-07-29 15:29:06

示例字符串的开头是这样的:Successful hires will expand the group's。MySQL会将group's中的单引号解释为SELECT语句中字符串条件的结束。为了实现这一点,在数据库中存储文本并在需要时反转时,必须用''替换每个'

票数 0
EN

Stack Overflow用户

发布于 2021-07-29 15:16:33

你需要这样的东西:

代码语言:javascript
复制
  create table #scrappedjobs
    (
       JobDescription NVARCHAR(1000)
    )
    
    insert into #scrappedjobs (JobDescription)
    VALUES('"<div class="article__content">"')
    
    select * from #scrappedjobs
    
    SELECT COUNT(*) FROM #scrappedjobs WHERE JobDescription = '"<div class="article__content">"'

-- Second select with like :
    SELECT COUNT(*) FROM #scrappedjobs WHERE JobDescription like '%"<div class="article__content">"%' 

请记住,您需要在JobDescription值的开始和结束位置使用‘。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68571409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档