wrong code, restarted project wwww
Asked
Active
Viewed 648 times
0
-
Maybe you mean't `.find_all("script")[1]` ? – Sebastien D Jun 15 '19 at 15:53
-
Please explain exactly what you are after from that script tag – QHarr Jun 15 '19 at 17:02
2 Answers
1
You cannot utilize BeautifulSoup for parsing Javascript data, but you can use re module (data is your HTML code):
import re
from bs4 import BeautifulSoup
soup = BeautifulSoup(data, 'lxml')
txt = soup.select('.Actions script')[1].text
print(re.search(r'sharedPaymentUrl:\s*"(.*?)"', txt)[1])
Prints:
https://secure.ewaypayments.com/sharedpage/sharedpayment?AccessCode=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==
Andrej Kesely
- 118,151
- 13
- 38
- 75
-
You need to post some data to the site (e.g. using `requests.post()`). Just getting the page `https://www.supplystore.com.au/shop/checkout/submit.aspx` doesn't contain your data. – Andrej Kesely Jun 16 '19 at 05:46
0
Another way using bs4 4.7.1. :contains and split
from bs4 import BeautifulSoup as bs
#html would be response text e.g. r = requests.get(url): soup = bs(r.content, 'lxml')
html = '''
<div class="Actions">
<input class="action" type="submit" id="submit-button" value="Place Order" title="Place Order" onclick="return showModal()" disabled="disabled" />
<input type="hidden" id="EWAY_TransactionID" name="EWAY_TransactionID" value="" />
<script src="https://secure.ewaypayments.com/scripts/eCrypt.js"> </script>
<script type="text/javascript">
var eWAYConfig = {
sharedPaymentUrl: "https://secure.ewaypayments.com/sharedpage/sharedpayment?AccessCode=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=="
};
function showModal()
{
// verify captcha
// show modal
return eCrypt.showModalPayment(eWAYConfig, resultCallback);
}
function resultCallback(result, transactionID, errors) {
if (result == "Complete") {
document.getElementById("EWAY_TransactionID").value = transactionID;
document.getElementById("Form_PaymentForm").submit();
//Please wait until we process your order, James at 9/10/2017
document.getElementById("overlay").style.display = "block";
}
else if (errors != "")
{
alert("There was a problem completing the payment: " + errors);
}
}
</script>
'''
soup = bs(html, 'lxml')
target = 'sharedPaymentUrl: '
script = soup.select_one('.Actions script:contains("' + target + '")')
if script is None:
url = 'N/A'
else:
url = script.text.split(target)[1].split('\n')[0]
print(url)
QHarr
- 80,579
- 10
- 51
- 94