Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用刮纸和美容器刮网_Python_Beautifulsoup_Scrapy - Fatal编程技术网

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