![](/img/trans.png)
[英]How to append an element inside a link after the first text element with JavaScript?
[英]How to get the text of an element inside a link with python
我需要一個簡單的腳本,可以在其中輸入網址,並且可以獲取頁面中某個html元素的文本。 例如:在https://www.transfermarkt.co.uk/schnellsuche/ergebnis/schnellsuche?query=Daley+Blind&x=0&y=0內,我需要具有“位置”(在這種情況下為CB)並記錄其控制台例如在我的頁面中。
謝謝
您可以簡單地將此URL作為字符串,然后使用split方法對字符串進行相應的拆分。
如果網址始終相似,即格式始終相同,那么您可以執行以下操作。
s="https://www.transfermarkt.co.uk/schnellsuche/ergebnis/schnellsuche?query=Daley+Blind&x=0&y=0"
s=s.strip("&")
x=s[-2]
y=s[-1]
x=x.split("=")
y=y.split("=")
xCord=x[-1]
yCord=y[-1]
如果您希望HTML元素形成頁面。 您可以執行以下操作:
from bs4 import BeautifulSoup
import requests
url="Your url"
source=requests.get(url).text
soup=BeautifulSoup(source,"lxml")
# the div block of element id or even class
element=soup.find('div',id='your id')
print(element)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.