Python 用刮纸和美容器刮网
我总是得不到回应 你们能帮帮我吗?我是新来的美人儿,对它不太放心Python 用刮纸和美容器刮网,python,beautifulsoup,scrapy,Python,Beautifulsoup,Scrapy,我总是得不到回应 你们能帮帮我吗?我是新来的美人儿,对它不太放心 多谢各位 在美化组中可以使用键值访问属性。就像一本字典 Ex: 'geocoordinates':['class','result-item-name','data-localisation'] from bs4 import BeautifulSoup html = """<h2 class="result-item-name" data-nid="117" data-localisation="25.88872, -8
多谢各位 在
美化组中
可以使用键值访问属性。就像一本字典
Ex:
'geocoordinates':['class','result-item-name','data-localisation']
from bs4 import BeautifulSoup
html = """<h2 class="result-item-name" data-nid="117" data-localisation="25.88872, -80.12488">Bal Harbour </h2>"""
soup = BeautifulSoup(html, "html.parser")
h2 = soup.find("h2", class_= "result-item-name")
print(h2["data-nid"])
print(h2["data-localisation"])
请提供一个可复制的示例和代码的其余部分。如果不了解您迄今为止所做的工作,就很难帮助您。您好,欢迎来到Stack Overflow!。为了得到更好的答案,请按照这些指南创建一个新的答案。
from bs4 import BeautifulSoup
html = """<h2 class="result-item-name" data-nid="117" data-localisation="25.88872, -80.12488">Bal Harbour </h2>"""
soup = BeautifulSoup(html, "html.parser")
h2 = soup.find("h2", class_= "result-item-name")
print(h2["data-nid"])
print(h2["data-localisation"])
117
25.88872, -80.12488
from bs4 import BeautifulSoup
html = """
<h2 class="result-item-name" data-nid="117" data-localisation="25.88872, -80.12488">
Bal Harbour
</h2>
"""
soup = BeautifulSoup(html, 'html.parser')
h2 = soup.find('h2', {'class': 'result-item-name'})
print(h2['data-nid'])
print(h2['data-localisation'])
117
25.88872, -80.12488