【发布时间】:2017-09-16 21:32:05
【问题描述】:
我是 Python 新手,我正在使用 BeautifulSoup 在 Python 中编写一个小爬虫,以便从网页中获取地址。我附上了它的图片 enter image description here
</div>
</div>
<div data-integration-name="redux-container" data-payload='{"name":"LocationsMapList","props":{"locations":[{"id":17305,"company_id":106906,"description":"","city":"New York","country":"United States","address":"5 Crosby St 3rd Floor","state":"New York","region":"","latitude":40.719753,"longitude":-74.0001954,"hq":true,"created_at":"2015-01-19T01:32:16.317Z","updated_at":"2016-05-05T07:57:19.282Z","zip_code":"10013","country_code":"US","full_address":"5 Crosby St 3rd Floor, New York, 10013, New York, USA","dirty":false,"to_params":"new-york-us"}]},"storeName":null}' data-rwr-element="true">
我使用 BeautifulSoup 获得了完整的内容,但我不知道如何提取“full_address”的内容。我看到它在“div”中,但我不知道下一步该做什么。
links = soup.find_all('div')
非常感谢!
【问题讨论】:
-
(请将您的代码添加为文本而不是图片)
-
我添加了它。谢谢!
-
'data-payload'属性是json,所以使用json.loads -
如果您不熟悉 html 的命名法 - W3C Tutorial。 The BeautifulSoup docs 有一些很好的基础 - 如果您通读它并牢记您的问题,您可能会开始看到解决方案。
-
您可能还想花一些时间通过the Python Tutorial 了解可供您使用的工具。请阅读How to Ask 和minimal reproducible example。
标签: python web beautifulsoup screen-scraping