Py学习  »  Python

用python进行网页抓取,javascript输出

user16674073 • 3 年前 • 1180 次点击  

我正试图从这个网站上删除工作信息,已经被困了几天。当我打印汤的时候。文本输出我得到一个简短的javascript文本,它不是我想要的,因为我想要html元素。我见过类似的解决方案来实现“无标题浏览”,但当我实现时,我只收到了几个错误。我对网络抓取还不熟悉,看过各种教程和视频,只是没有得到我想要的输出,也不知道我做错了什么。

import requests
from bs4 import BeautifulSoup



def aSwiftScraper():

    jobLinks = []
    pages = []
    URL = "https://www.amiqus.com/jobs?options=,20993,20877,20876&page=1"
    page = requests.get(URL)
    soup = BeautifulSoup(page.content, "html.parser")
    print(soup.text)


aSwiftScraper()
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130628
 
1180 次点击  
文章 [ 1 ]  |  最新文章 3 年前
Andrej Kesely
Reply   •   1 楼
Andrej Kesely    3 年前

试着改变 User-Agent 向服务器发出请求时的HTTP头:

import requests
from bs4 import BeautifulSoup

headers = {
    "User-Agent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
}

url = "https://www.amiqus.com/jobs?options=,20993,20877,20876&page=1"

soup = BeautifulSoup(requests.get(url, headers=headers).content, "html.parser")
for title in soup.select(".attrax-vacancy-tile__title"):
    print(title.get_text(strip=True))

印刷品:

Engine Programmer C++ AAA opportunity - Remote working
Senior Programmer
Gameplay Programmer

...