【发布时间】:2026-01-09 12:10:01
【问题描述】:
这是我第一次进行网络抓取,我正在关注tutorial。我正在使用这个website 来抓取信息。我正在尝试获取“89426 Green Mountain Road, Astoria, OR 97103。电话:503-325-9720”的文字。我注意到我的div class_=alert 标签中有多个ul 和li 标签。所以我不知道如何抓住一个特定的。这是我尝试过的,但继续从另一组ul/li 获得不同的文本。
from bs4 import BeautifulSoup
import requests
source = requests.get('https://www.pickyourownchristmastree.org/ORxmasnw.php').text
soup = BeautifulSoup(source, 'lxml')
noble_ridge = soup.find('div', class_='alert')
information = noble_ridge.ul.li.text
print(information)
# print(soup.prettify())
C:\Users\name\anaconda3\envs\Scraping\python.exe C:/Users/name/PycharmProjects/Scraping/Christmas_tree_farms.py
If the name of the farm is blue with an underline; that's a link to their website. Click on it for the most current hours and information.
Process finished with exit code 0
【问题讨论】:
-
您好 - 亲爱的 Zman3 美好的一天 - 非常感谢您拿起 Curey Schafer 的刮刀。太棒了——太棒了。继续做伟大的工作 - 它摇滚
标签: web-scraping beautifulsoup pycharm