我尝试从我的 base_url 页面中抓取特定行(图中标记为蓝色圆圈)。页面源代码在另一张图片中。
我的目标是获取这些
我的代码:
from bs4 import BeautifulSoup
from selenium import webdriver
import requests, csv, re, pandas, numpy
base_url = "http://www.basket.fi/sarjat/ottelu/?game_id=3502579&season_id=93783&league_id=4+"+"#mbt:2-400$t&0=1"
browser = webdriver.PhantomJS()
browser.get(base_url)
table = BeautifulSoup(browser.page_source, 'lxml')
for data in table.find_all("tr",{"class":"row2"}):
print(data.find("td").text)
最佳答案
通常您可以通过属性选择 html 元素,但对于本文档,“class”属性并不是很有帮助,因为同一类中还有许多其他“tr”标签。
在这种情况下,您可以使用列表索引来选择标签。
for td in table.find_all("tr", {"class":"row2"})[25].find_all('td')[1:]:
print(td.get_text(strip=True))
关于python - 使用 BeautifulSoup 抓取特定的表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46222995/
上一篇:python - ImportError:没有名为weather_Core_Engine.weather_DB_Handler的模块
下一篇:python - python中使用select从多个连接接收数据
相关文章:
Python pandas 没有属性 ols - 错误(滚动 OLS)
java - 迭代 LinkedHashMap 并在新行上返回每个 ‘String’ 元素
python - 如何找到并单击带有 Selenium 的隐藏按钮?
python - ExpectedCondition.invisibility_of_element_located 需要更多时间(selenium web driver-python)
Python raw_input 使用 TAB 而不是 ENTER?
python - Flask 和 SQLAlchemy 的 "unexpected EOF on client connection"
python - 简单的 Python UDP 服务器 : trouble receiving packets from clients other than localhost