Add custom attribute without quotes2019 Community Moderator ElectionSingle quotes vs. double quotes in PythonHow do I check whether a file exists without exceptions?How to print without newline or space?How to know if an object has an attribute in PythonAdd new keys to a dictionary?Proper way to declare custom exceptions in modern Python?Peak detection in a 2D array“Large data” work flows using pandasCannot display HTML stringHow to extract attribute of selected tags if the attribute is available and skip if not with python BeautifulSoup

What is knowledge and vision?

What is a term for a function that when called repeatedly, has the same effect as calling once?

Did 5.25" floppies undergo a change in magnetic coating?

How to approximate rolls for potions of healing using only d6's?

What do the pedals on grand pianos do?

In the comics Did Thanos "kill" just sentient beings or all creatures with the snap?

What's the difference between a cart and a wagon?

Non-Italian European mafias in USA?

How can atoms be electrically neutral when there is a difference in the positions of the charges?

Magento 2: Override XML file from vendor folder to app folder doesn't work/update

What is this waxed root vegetable?

Whom do I have to contact for a ticket refund in case of denied boarding (in the EU)?

Can we carry rice to Japan?

Where is the fallacy here?

Is there a German word for “analytics”?

Pure Functions: Does "No Side Effects" Imply "Always Same Output, Given Same Input"?

I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?

Rationale to prefer local variables over instance variables?

Wrap all numerics in JSON with quotes

Is there any relevance to Thor getting his hair cut other than comedic value?

Is there a frame of reference in which I was born before I was conceived?

What type of postprocessing gives the effect of people standing out

Linear regression when Y is bounded and discrete

Why do members of Congress in committee hearings ask witnesses the same question multiple times?



Add custom attribute without quotes



2019 Community Moderator ElectionSingle quotes vs. double quotes in PythonHow do I check whether a file exists without exceptions?How to print without newline or space?How to know if an object has an attribute in PythonAdd new keys to a dictionary?Proper way to declare custom exceptions in modern Python?Peak detection in a 2D array“Large data” work flows using pandasCannot display HTML stringHow to extract attribute of selected tags if the attribute is available and skip if not with python BeautifulSoup










0















I'm trying to add an attribute to a HTML tag without quotes, so I can add a slash before the quotes and add the quotes manually.



The src attribute needs to stay empty, I can't rename it.



My current code looks like this.



for img in soup.find_all(name="img"):
src = img['src']
img.attrs['data-src'] = src


My result (after saving it to a file):



<img src="" data-src='"/folder/img/image.jpg"'>


What I'm looking for:



<img src="/folder/img/image.jpg">


What I'm trying is:

Load in db.sql with Bs4

Set src-data attribute to src value

Clear value of src attribute

Save file to db2.sql










share|improve this question









New contributor




JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    0















    I'm trying to add an attribute to a HTML tag without quotes, so I can add a slash before the quotes and add the quotes manually.



    The src attribute needs to stay empty, I can't rename it.



    My current code looks like this.



    for img in soup.find_all(name="img"):
    src = img['src']
    img.attrs['data-src'] = src


    My result (after saving it to a file):



    <img src="" data-src='"/folder/img/image.jpg"'>


    What I'm looking for:



    <img src="/folder/img/image.jpg">


    What I'm trying is:

    Load in db.sql with Bs4

    Set src-data attribute to src value

    Clear value of src attribute

    Save file to db2.sql










    share|improve this question









    New contributor




    JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      0












      0








      0








      I'm trying to add an attribute to a HTML tag without quotes, so I can add a slash before the quotes and add the quotes manually.



      The src attribute needs to stay empty, I can't rename it.



      My current code looks like this.



      for img in soup.find_all(name="img"):
      src = img['src']
      img.attrs['data-src'] = src


      My result (after saving it to a file):



      <img src="" data-src='"/folder/img/image.jpg"'>


      What I'm looking for:



      <img src="/folder/img/image.jpg">


      What I'm trying is:

      Load in db.sql with Bs4

      Set src-data attribute to src value

      Clear value of src attribute

      Save file to db2.sql










      share|improve this question









      New contributor




      JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I'm trying to add an attribute to a HTML tag without quotes, so I can add a slash before the quotes and add the quotes manually.



      The src attribute needs to stay empty, I can't rename it.



      My current code looks like this.



      for img in soup.find_all(name="img"):
      src = img['src']
      img.attrs['data-src'] = src


      My result (after saving it to a file):



      <img src="" data-src='"/folder/img/image.jpg"'>


      What I'm looking for:



      <img src="/folder/img/image.jpg">


      What I'm trying is:

      Load in db.sql with Bs4

      Set src-data attribute to src value

      Clear value of src attribute

      Save file to db2.sql







      python python-3.x beautifulsoup






      share|improve this question









      New contributor




      JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 28 mins ago







      JeroenR













      New contributor




      JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 57 mins ago









      JeroenRJeroenR

      12




      12




      New contributor




      JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      JeroenR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Use del to remove attributes:



          for img in soup.find_all(name="img"):
          src = img['src']
          del img['src']
          img.attrs['data-src'] = src





          share|improve this answer























          • I'm not looking to delete the src attribute. The problem is the single quotes around the new value, I don't want them.

            – JeroenR
            49 mins ago











          • @JeroenR Ah I misread your desired output. However, there are no single quotes around the resulting tag. They are only displayed in your Python console because that’s how strings are displayed; compare "hello" vs print("hello").

            – Konrad Rudolph
            47 mins ago











          • I'm loading in a .sql file, read / modify the html with bs4 and rewrite it to a new .sql file. When that happens I get single quotes around my values (inside the sql file)

            – JeroenR
            37 mins ago











          • @JeroenR If that’s the case then that’s due to how you write the SQL code, not due to your manipulation of the HTML document. In other words, it’s unrelated, and you will have the same issue with the original, unmodified document.

            – Konrad Rudolph
            36 mins ago










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          JeroenR is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55001447%2fadd-custom-attribute-without-quotes%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Use del to remove attributes:



          for img in soup.find_all(name="img"):
          src = img['src']
          del img['src']
          img.attrs['data-src'] = src





          share|improve this answer























          • I'm not looking to delete the src attribute. The problem is the single quotes around the new value, I don't want them.

            – JeroenR
            49 mins ago











          • @JeroenR Ah I misread your desired output. However, there are no single quotes around the resulting tag. They are only displayed in your Python console because that’s how strings are displayed; compare "hello" vs print("hello").

            – Konrad Rudolph
            47 mins ago











          • I'm loading in a .sql file, read / modify the html with bs4 and rewrite it to a new .sql file. When that happens I get single quotes around my values (inside the sql file)

            – JeroenR
            37 mins ago











          • @JeroenR If that’s the case then that’s due to how you write the SQL code, not due to your manipulation of the HTML document. In other words, it’s unrelated, and you will have the same issue with the original, unmodified document.

            – Konrad Rudolph
            36 mins ago















          0














          Use del to remove attributes:



          for img in soup.find_all(name="img"):
          src = img['src']
          del img['src']
          img.attrs['data-src'] = src





          share|improve this answer























          • I'm not looking to delete the src attribute. The problem is the single quotes around the new value, I don't want them.

            – JeroenR
            49 mins ago











          • @JeroenR Ah I misread your desired output. However, there are no single quotes around the resulting tag. They are only displayed in your Python console because that’s how strings are displayed; compare "hello" vs print("hello").

            – Konrad Rudolph
            47 mins ago











          • I'm loading in a .sql file, read / modify the html with bs4 and rewrite it to a new .sql file. When that happens I get single quotes around my values (inside the sql file)

            – JeroenR
            37 mins ago











          • @JeroenR If that’s the case then that’s due to how you write the SQL code, not due to your manipulation of the HTML document. In other words, it’s unrelated, and you will have the same issue with the original, unmodified document.

            – Konrad Rudolph
            36 mins ago













          0












          0








          0







          Use del to remove attributes:



          for img in soup.find_all(name="img"):
          src = img['src']
          del img['src']
          img.attrs['data-src'] = src





          share|improve this answer













          Use del to remove attributes:



          for img in soup.find_all(name="img"):
          src = img['src']
          del img['src']
          img.attrs['data-src'] = src






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 55 mins ago









          Konrad RudolphKonrad Rudolph

          400k1017871036




          400k1017871036












          • I'm not looking to delete the src attribute. The problem is the single quotes around the new value, I don't want them.

            – JeroenR
            49 mins ago











          • @JeroenR Ah I misread your desired output. However, there are no single quotes around the resulting tag. They are only displayed in your Python console because that’s how strings are displayed; compare "hello" vs print("hello").

            – Konrad Rudolph
            47 mins ago











          • I'm loading in a .sql file, read / modify the html with bs4 and rewrite it to a new .sql file. When that happens I get single quotes around my values (inside the sql file)

            – JeroenR
            37 mins ago











          • @JeroenR If that’s the case then that’s due to how you write the SQL code, not due to your manipulation of the HTML document. In other words, it’s unrelated, and you will have the same issue with the original, unmodified document.

            – Konrad Rudolph
            36 mins ago

















          • I'm not looking to delete the src attribute. The problem is the single quotes around the new value, I don't want them.

            – JeroenR
            49 mins ago











          • @JeroenR Ah I misread your desired output. However, there are no single quotes around the resulting tag. They are only displayed in your Python console because that’s how strings are displayed; compare "hello" vs print("hello").

            – Konrad Rudolph
            47 mins ago











          • I'm loading in a .sql file, read / modify the html with bs4 and rewrite it to a new .sql file. When that happens I get single quotes around my values (inside the sql file)

            – JeroenR
            37 mins ago











          • @JeroenR If that’s the case then that’s due to how you write the SQL code, not due to your manipulation of the HTML document. In other words, it’s unrelated, and you will have the same issue with the original, unmodified document.

            – Konrad Rudolph
            36 mins ago
















          I'm not looking to delete the src attribute. The problem is the single quotes around the new value, I don't want them.

          – JeroenR
          49 mins ago





          I'm not looking to delete the src attribute. The problem is the single quotes around the new value, I don't want them.

          – JeroenR
          49 mins ago













          @JeroenR Ah I misread your desired output. However, there are no single quotes around the resulting tag. They are only displayed in your Python console because that’s how strings are displayed; compare "hello" vs print("hello").

          – Konrad Rudolph
          47 mins ago





          @JeroenR Ah I misread your desired output. However, there are no single quotes around the resulting tag. They are only displayed in your Python console because that’s how strings are displayed; compare "hello" vs print("hello").

          – Konrad Rudolph
          47 mins ago













          I'm loading in a .sql file, read / modify the html with bs4 and rewrite it to a new .sql file. When that happens I get single quotes around my values (inside the sql file)

          – JeroenR
          37 mins ago





          I'm loading in a .sql file, read / modify the html with bs4 and rewrite it to a new .sql file. When that happens I get single quotes around my values (inside the sql file)

          – JeroenR
          37 mins ago













          @JeroenR If that’s the case then that’s due to how you write the SQL code, not due to your manipulation of the HTML document. In other words, it’s unrelated, and you will have the same issue with the original, unmodified document.

          – Konrad Rudolph
          36 mins ago





          @JeroenR If that’s the case then that’s due to how you write the SQL code, not due to your manipulation of the HTML document. In other words, it’s unrelated, and you will have the same issue with the original, unmodified document.

          – Konrad Rudolph
          36 mins ago












          JeroenR is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          JeroenR is a new contributor. Be nice, and check out our Code of Conduct.












          JeroenR is a new contributor. Be nice, and check out our Code of Conduct.











          JeroenR is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55001447%2fadd-custom-attribute-without-quotes%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Runtime problems in TestNG asserts2019 Community Moderator ElectionHow do you assert that a certain exception is thrown in JUnit 4 tests?differences between 2 JUnit Assert classesHow do I use Assert to verify that an exception has been thrown?Best practice for Python assertWhat is the “assert” function?What does the Java assert keyword do, and when should it be used?What is the use of “assert” in Python?PHPUnit assert that an exception was thrown?What is “assert” in JavaScript?Asserting in testng using containing

          (unchecked) unchecked cast required: OnSuccessListener found: Uri2019 Community Moderator ElectionHow do I address unchecked cast warnings?Android AlarmManager for periodical sensor readingWhy don't Java's +=, -=, *=, /= compound assignment operators require casting?I am trying to set alarm on specific time using alarm manager but alarm initiated instantly?setText on button from another activity androidget around of error 'can not resolve symbol'Saving ToggleButton state in ListView by using SharedPreferencesAdding Social Media Share Logic From Firebase in Androidjava.lang.NullPointerException when invoking onLoadFinished()Search Firestore query don't show data in RecycleView

          1