【发布时间】:2019-03-22 15:24:44
【问题描述】:
我正在做一个简单的爬虫来从 steamDB (https://steamdb.info/sales/?min_discount=50&min_rating=70) 中提取 Steam 销售信息。这是我的代码:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://steamdb.info/sales/?min_discount=50&min_rating=70")
# extract the sale table and list of entries
table = driver.find_element_by_xpath("//*[@id='DataTables_Table_0']/tbody")
# key info: name/ price/ discount/ rating/ end time/ appid
for i in driver.find_elements_by_xpath(".//tr"):
for cnt, td in enumerate(i.find_elements_by_xpath(".//td")):
print(cnt, td.text)
print(i.get_attribute("data-appid"))
print("===========================")
基本上我只是发现表格包含所有销售信息,并提取游戏名称,价格,折扣,销售开始时间,结束时间等关键文本。
但是,在表格中的几行数据之后,我发现销售结束/开始/游戏发布时间的文字缺失:
这是一个不错的样子:
0
1
2 Undertale
Daily Deal
3 -61%
4 ¥ 14
5 94.18%
6 2 hours # sales end in
7 2 days ago # sales start from
8 4 years ago # game released
391540 # appid
===========================
这是一个糟糕的样子:
0
1
2 South Park™: The Stick of Truth™
Ubisoft Publisher Weekend new highest discount
3 -80%
4 $5.99
5 95.53%
6
7
8
213670
如您所见,爬虫可以检测到索引 6、7、8 中的 td 标签,但无法从中提取任何文本。
一些观察:
- 我检查了 dom 并没有发现两者之间的任何区别 一排好一坏一排
- 该问题仅在大约前 10 行后重现
【问题讨论】:
标签: python selenium web-scraping selenium-chromedriver