UYOU
您需要通过请求主网址一次来获取cookie,然后在 上发送POST。但这也需要一些必需的URL参数JESSIONIDhttps://echa.europa.eu/search-for-chemicals用卷曲和砰:query="71-23-8"millis=$(($(date +%s%N)/1000000))curl -s -I -c cookie.txt 'https://echa.europa.eu/search-for-chemicals'curl -s -L -b cookie.txt 'https://echa.europa.eu/search-for-chemicals' \ --data-urlencode "p_p_id=disssimplesearch_WAR_disssearchportlet" \ --data-urlencode "p_p_lifecycle=1" \ --data-urlencode "p_p_state=normal" \ --data-urlencode "p_p_col_id=column-1" \ --data-urlencode "p_p_col_count=2" \ --data-urlencode "_disssimplesearch_WAR_disssearchportlet_javax.portlet.action=doSearchAction" \ --data-urlencode "_disssimplesearch_WAR_disssearchportlet_backURL=https://echa.europa.eu/home?p_p_id=disssimplesearchhomepage_WAR_disssearchportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=2" \ --data-urlencode "_disssimplesearchhomepage_WAR_disssearchportlet_sessionCriteriaId=" \ --data "_disssimplesearchhomepage_WAR_disssearchportlet_formDate=$millis" \ --data "_disssimplesearch_WAR_disssearchportlet_searchOccurred=true" \ --data "_disssimplesearch_WAR_disssearchportlet_sskeywordKey=$query" \ --data "_disssimplesearchhomepage_WAR_disssearchportlet_disclaimer=on" \ --data "_disssimplesearchhomepage_WAR_disssearchportlet_disclaimerCheckbox=on"用蟒和刮擦美丽的豆汤import requestsfrom bs4 import BeautifulSoupimport timeurl = 'https://echa.europa.eu/search-for-chemicals'query = '71-23-8's = requests.Session()s.get(url)r = s.post(url, params = { "p_p_id": "disssimplesearch_WAR_disssearchportlet", "p_p_lifecycle": "1", "p_p_state": "normal", "p_p_col_id": "column-1", "p_p_col_count": "2", "_disssimplesearch_WAR_disssearchportlet_javax.portlet.action": "doSearchAction", "_disssimplesearch_WAR_disssearchportlet_backURL": "https://echa.europa.eu/home?p_p_id=disssimplesearchhomepage_WAR_disssearchportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=2", "_disssimplesearchhomepage_WAR_disssearchportlet_sessionCriteriaId": "" }, data = { "_disssimplesearchhomepage_WAR_disssearchportlet_formDate": int(round(time.time() * 1000)), "_disssimplesearch_WAR_disssearchportlet_searchOccurred": "true", "_disssimplesearch_WAR_disssearchportlet_sskeywordKey": query, "_disssimplesearchhomepage_WAR_disssearchportlet_disclaimer": "on", "_disssimplesearchhomepage_WAR_disssearchportlet_disclaimerCheckbox": "on" })soup = BeautifulSoup(r.text, "html.parser")table = soup.find("table")data = [ ( t[0].find("a").text.strip(), t[0].find("a")["href"], t[0].find("div", {"class":"substanceRelevance"}).text.strip(), t[1].text.strip(), t[2].text.strip(), t[3].find("a")["href"] if t[3].find("a") else "", t[4].find("a")["href"] if t[4].find("a") else "", ) for t in (t.find_all('td') for t in table.find_all("tr")) if len(t) > 0 and t[0].find("a") is not None]print(data)请注意,我已经设置了时间戳参数(formDate参数),以防它在服务器上实际检查