Using python requests and beautiful soup to pull text

后端 未结 1 690
名媛妹妹
名媛妹妹 2021-01-13 08:22

thanks for taking a look at my problem. i would like to know if there is any way to pull the data-sitekey from this text... here is the url to the page https://e-com.secure.

相关标签:
1条回答
  • 2021-01-13 08:47

    Ok now we have code, it is as simple as:

    import requests
    from bs4 import BeautifulSoup
    
    
    soup = BeautifulSoup(requests.get("https://e-com.secure.force.com/adidasUSContact/").content, "html.parser")
    
    key = soup.select_one("#ncaptchaRecaptchaId")["data-sitekey"]
    

    data-sitekey is an attribute, not a css class so you just need to extract it from the element, you can find the element by it's id as above.

    You could also use the class name:

    # css selector
    key = soup.select_one("div.g-recaptcha")["data-sitekey"]
    # regular find using class name
    key = soup.find("div",class_="g-recaptcha")["data-sitekey"]
    
    0 讨论(0)
提交回复
热议问题