我试图从一个网页(网址如下)刮产品的链接.该页面使用的是JavaScript.我try 了不同的库,但链接没有显示在结果中(这些链接的格式是*/product/*
,当你打开下面的URL时,你可以通过将鼠标悬停在产品链接上看到).
url = 'https://www.bcliquorstores.com/product-catalogue?categoryclass=coolers%20%26%20ciders&special=new%20product&sort=name.raw:asc&page=1'
headers = {
'Host': 'www.bcliquorstores.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.7,fa;q=0.3',
}
使用requests
个库:
import requests
res = requests.get(url, headers=headers)
使用urllib
个库
import urllib.request
request = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(request)
response.read().decode()
使用requests_html
个库:
from requests_html import HTMLSession, AsyncHTMLSession
asession = AsyncHTMLSession()
r = await asession.get(url, headers=headers)
await r.html.arender()
res = r.html.html
当我在结果中搜索字符串/product/
时,找不到它,但从Inspect窗口中可以看到它.
我知道selenium,但我只想在没有其他方法的情况下使用它.