What is the best way to change html using python? [closed] - html

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 days ago.
Improve this question
I want to find all inclusion of my pattern in a html page and then chage it. But I can't get text for second case when there is tag span between Word1 and Word2.
from bs4 import BeautifulSoup
import re
html_doc = """<html><head><title>Word1 Word2</title></head>
<body><p class="title"><b>Word1 <span>Word2</span></b></p></body></html>"""
soup = BeautifulSoup(html_doc, 'html.parser')
pattern = re.compile(r'Word1.*Word2')
target = soup.find_all(string=pattern) # Output ['Word1 Word2']
for v in target:
v.replace_with(v.replace('Word1 Word2', 'Word3 Word4'))
print(soup) #Output: <html><head><title>Word3 Word4</title></head>
#<body><p class="title"><b>Word1 <span>Word2</span></b></p></body></html>
I tried to change html fully, but It changed partly.How Can I fix it?

Related

Regular expression to replace same patterns with another string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a string below that I want to replace all /data/.*/www with /www.
StackTrace::getCurrent() at
/data/users/eaminz/www/flib/intern/scripts/insights/msis/workflows/messaging/MSISWorkFlowLoggerSingleton.php:102#r0\nMSISWorkFlowLoggerSingleton::errorWrongConfig()
at
/data/users/eaminz/www/flib/intern/insights/simplification/ads/codegen/api/business_insights/BusinessInsightsAPIMetricCodegen.php:89#r0\nBusinessInsightsAPIMetricCodegen::generateStorageCode()
at
/data/users/eaminz/www/flib/intern/insights/simplification/ads/codegen/api/business_insights/BusinessInsightsAPIMetricCodegen.php:40#r0\nBusinessInsightsAPIMetricCodegen::generateCode()
at
/data/users/eaminz/www/flib/intern/scripts/insights/msis/codegen/InsightsAPIMetricSimplificationScriptController.php:380#r0\nInsightsAPIMetricSimplificationScriptController->generateProductSpecificStorageCode()
at
/data/users/eaminz/www/flib/intern/scripts/insights/msis/codegen/InsightsAPIMetricSimplificationScriptController.php:285#r0\nInsightsAPIMetricSimplificationScriptController->genMetricCode()
at
/data/users/eaminz/www/flib/intern/scripts/insights/msis/codegen/InsightsAPIMetricSimplificationScriptController.php:200#r0\nInsightsAPIMetricSimplificationScriptController->genRunImpl()
at
/data/users/eaminz/www/flib/intern/scripts/insights/msis/codegen/InsightsAPIMetricSimplificationScriptController.php:113#r0\nInsightsAPIMetricSimplificationScriptController->genRun()
at
/data/users/eaminz/www/flib/intern/scripts/controller/ScriptController.php:189#r0\nScriptController->__genRunWithCommandLineArgs()
at
/data/users/eaminz/www/flib/intern/scripts/controller/ScriptController.php:111#r0\nScriptController::__genDispatch()
at
/data/users/eaminz/www/scripts/bin/phps_init.php:23#r0\nphps_init_entrypoint()
at :0#r0\nClosure$__SystemLib\enter_async_entry_point() at
:0#r0\nHH\Asio\join() at :0#r0\n__SystemLib\enter_async_entry_point()
at :0#r0
So it should become something like the following:
StackTrace::getCurrent() at
/www/flib/intern/scripts/insights/msis/workflows/messaging/MSISWorkFlowLoggerSingleton.php:102#r0\nMSISWorkFlowLoggerSingleton::errorWrongConfig()
at
/www/flib/intern/insights/simplification/ads/codegen/api/business_insights/BusinessInsightsAPIMetricCodegen.php:89#r0\nBusinessInsightsAPIMetricCodegen::generateStorageCode()
at
I tried /data/.*[^/]www/ to find all the patterns but no use. Could someone please help? Thank you!
Try this:
\/data\/.*?\/www
Demo

How can I create bulk Hyperlinks (Parts 1 - 100) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am currently creating a website and I have come across the problem of having over 100 links and I don't know how to Hyperlink every single one.
Lets say I wanted to structure it like
<a href="link.com/1-5JKFKS" target="_blank">Part 1</>
<a href="link.com/2-5KWMAS" target="_blank">Part 2</>
<a href="link.com/3-42JNSL" target="_blank">Part 3</>
How would one go about creating 106 links formatted like this. I'm not exactly sure what I am looking for or even what is required to do this. So I'm sorry for how broad the question is.
I created a program in C# to create it for me. If anyone ever needs it I can give out the source code.
https://i.imgur.com/7csfx3V.gifv
I don't quite understand what you're asking for, but this would work as far as I can tell:
var nOfLinks = 100;
for (var i = 1; i <= nOfLinks; i++) {
document.getElementById("links").innerHTML += "<a href=\"link.com/" + i + "\" target=\"_blank\">Part " + i + "</><br/>"
}
<div id="links">
</div>
If you can use Emmet in the code editor you're using you can do it with something like this:
a[href="link.com/$" target="_blank"]{Part $}*106
With Emmet you just write this and usually press the tab key to expand the code into the full HTML.
That will output the links correctly.

how to get first JSONs elements using python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
The public API respond me with JSON which has the next format
{"ABCD-EFG":
{"param1":"0.1234",
"param2":"0.123456",
"param3":"0.12334254"},
"HIG-KLMN":
{"param1":"0.3456",
"param2":"0.05710"
"param3":"0.004903"
... }
How can i get the List of the names (in this examle ABCD-EFG, HIG-KLMN) using Python3 ?
They can make changes in it every API get request sending
If it was like 'name' : 'ABCD-EFG', it would be easy. But it's not like that.
There are a few ways, here's one:
x = {
"ABCD-EFG": {
"param1":"0.1234",
"param2":"0.123456",
"param3":"0.12334254"
},
"HIG-KLMN": {
"param1":"0.3456",
"param2":"0.05710",
"param3":"0.004903"
}
}
y = list(x.keys())
print(y)
for key in x.keys():
print(key)
gives:
['ABCD-EFG', 'HIG-KLMN']
ABCD-EFG
HIG-KLMN

I want to link each page by a different game_review_id by querystring but it gives me the in any link [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
This is in the source:
html.Append("<a href = 'http://localhost:50303/WebSite1/previewgamereview.aspx?id=game_review_id'>");
In the second file I wrote:
string id = Request.QueryString["id"];
html.Append("<a href = 'http://localhost:50303/WebSite1/previewgamereview.aspx?id=" + game_review_id + "'>");
In the second file:
if (Request.QueryString["id"] != null)
string id = Request.QueryString["id"].ToString();

mysql : find upper case Alphabets in like clause [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Need suggestion regarding finding all testimonial List contains link like http://www.example.com/UPPER CASE Letter
select * from testimonial3 where detail_text like '%http://www.example.com/Hind-global'
select * from testimonial3 where detail_text like '%http://www.example.com/Apple'
SELECT * FROM testimonial3 WHERE detail_text REGEXP BINARY 'http://www.example.com/[A-Z]{1}';