FTR我已经在两个框架中成功地编写了相当多的刮板,但我被难住了。以下是我试图抓取的数据的屏幕截图(您也可以转到get请求中的实际链接):

我尝试以div.section_content为目标
import requests
from bs4 import BeautifulSoup
html = requests.get("https://www.baseball-reference.com/boxes/ARI/ARI201803300.shtml").text
soup = BeautifulSoup(html)
soup.findAll("div", {"class": "section_content"})打印最后一行显示了其他一些div,但没有显示包含俯仰数据的div。
但是,我可以在文本中看到它,所以它不是javascript触发的加载问题(短语"Pitching“只出现在该表中):
>>> "Pitching" in soup.text
True以下是其中一个golang尝试的缩写版本:
package main
import (
"fmt"
"github.com/gocolly/colly"
)
func main() {
c := colly.NewCollector(
colly.AllowedDomains("www.baseball-reference.com"),
)
c.OnHTML("div.table_wrapper", func(e *colly.HTMLElement) {
fmt.Println(e.ChildText("div.section_content"))
})
c.Visit("https://www.baseball-reference.com/boxes/ARI/ARI201803300.shtml")}}
https://stackoverflow.com/questions/51299572
复制相似问题