标签: beautifulsoup

Python requests.get(url) 返回 javascript 代码而不是页面 html

我有一个非常简单的问题。我正在尝试从linkedIn 页面的html 中获取工作描述,但是我没有获取页面的html,而是得到了几行看起来像javascript 代码的行。我对此很陌生,因此将不胜感激任何帮助!谢谢

这是我的代码:

import requests
url = "https://www.linkedin.com/jobs/view/inside-sales-manager-at-stericycle-1089095836/"
page_html = requests.get(url).text
print(page_html)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我没有得到我期望包含工作描述的 html...我只是得到了几行 javascript 代码。

beautifulsoup web-scraping python-3.x python-requests

1
推荐指数
1
解决办法
4187
查看次数

从 BeautifulSoup 对象获取 URL

有人将他使用典型调用获得的 BeautifulSoup 对象 (BS4) 交给我的函数:

soup = BeautifulSoup(url)
Run Code Online (Sandbox Code Playgroud)

我的代码:

def doSomethingUseful(soup):
    url = soup.???
Run Code Online (Sandbox Code Playgroud)

如何从汤对象中获取原始 URL?我试着阅读文档和 BeautifulSoup 源代码......我仍然不确定。

python beautifulsoup

1
推荐指数
1
解决办法
7960
查看次数

无法使用 bs4 从 BSE 网站上抓取特定信息

我试图从这个网站上抓取之前的收盘价和开盘价。这是一张图像,作为要抓取的信息所在位置的参考。

股票信息表

看起来特定表是带有 的div标签的子表class="col-lg-13",但 bs4 只是None在所有尝试找到它时返回。

我尝试了以下方法:

from bs4 import BeautifulSoup
import requests

link = "https://bseindia.com/stock-share-price/bharat-gears-ltd/bharatgear/505688/"
resp = requests.get(link).content
soup = BeautifulSoup(resp, "lxml")

box = soup.find('div', class_="col-lg-13")
table = box.find('table')
print(table)

>>> None
Run Code Online (Sandbox Code Playgroud)

我也试过:

container = soup.find('div', attr={'ng-init': "fnStockTrading()"})
tables = container.find_all('table')
print(tables)

>>> []
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping

1
推荐指数
1
解决办法
341
查看次数

soup.select('.r a') in f'https://google.com/search?q={query}' 在 Python BeautifulSoup 中带回空列表。**不是复制品**

“我很幸运!” “使用 Python 自动化无聊的东西”电子书中的项目不再使用他提供的代码。

具体来说,linkElems = soup.select('.r a')

我已经尝试使用以下提供的解决方案: soup.select('.r a') in 'https://www.google.com/#q=vigilante+mic' 在 python BeautifulSoup 中给出空列表

,我目前使用相同的搜索格式。

import webbrowser, requests, bs4

def im_feeling_lucky():

    # Make search query look like Google's
    search = '+'.join(input('Search Google: ').split(" "))

    # Pull html from Google
    print('Googling...') # display text while downloading the Google page
    res = requests.get(f'https://google.com/search?q={search}&oq={search}')
    res.raise_for_status()

    # Retrieve top search result link
    soup = bs4.BeautifulSoup(res.text, features='lxml')


    # Open a browser tab for each result.
    linkElems = soup.select('.r')  # Returns empty list …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup python-webbrowser python-requests

1
推荐指数
1
解决办法
1677
查看次数

没有名为“BeautifulSoup”的模块?

我正在使用 Python3 并在我的 Mac 上下载了 BeautifulSoup,但它一直显示“没有名为 bs4 的模块”或“没有名为 BeautifulSoup 的模块”。我该怎么办?

这是 Coursera 上 Web Scraping 的 Py4E 的作业。

from bs4 import BeautifulSoup
Run Code Online (Sandbox Code Playgroud)

没有名为 bs4 的模块

$pip install BeautifulSoup 
Run Code Online (Sandbox Code Playgroud)

无效的语法

import BeautifulSoup from BeautifulSoup
Run Code Online (Sandbox Code Playgroud)

没有名为 BeautifulSoup 的模块

python beautifulsoup

1
推荐指数
1
解决办法
160
查看次数

beautifulsoup 只提取前 10 个元素

我试图从 kununu 上的大众汽车页面中提取信息。例如“Pro”信息。

url = 'https://www.kununu.com/de/volkswagen/kommentare'
page = requests.get(url)

soup = bs(page.text, 'html.parser')
divs = soup.find_all(class_="col-xs-12 col-lg-12")

for h2 in soup.find_all('h2', class_='h3', text=['Pro']):
    print(h2.find_next_sibling('p').get_text())
Run Code Online (Sandbox Code Playgroud)

但是作为输出,我只有前 10 个“Pro”。看起来它默认只显示前 10 条评论,但是所有不可见的评论都在“col-xs-12 col-lg-12”类下......或者我可能遗漏了一些你能帮我提取所有数据,而不仅仅是第一条10?

python beautifulsoup

1
推荐指数
1
解决办法
161
查看次数

用 BeautifulSoup 刮硬币市场

我想抓取此页面中包含的所有数据。不幸的是,我只能提取前三行。

import requests
from bs4 import BeautifulSoup

response = requests.get("https://www.coingecko.com/fr/pièces/bitcoin#markets")

soup = BeautifulSoup(response.text, "html.parser")
My_table = soup.find("table",{"class":"table table-scrollable"})
My_table
data = []
rows = My_table.find_all('tr')
for row in rows:
    cols = row.find_all('td')
    cols = [ele.text.strip() for ele in cols]
    data.append([ele for ele in cols if ele]) # Get rid of empty values
data 
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助

python beautifulsoup web-scraping

1
推荐指数
1
解决办法
482
查看次数

无法从网页中获取不同职位的标题

我已经使用 selenium 在 python 中编写了一个脚本来获取从网页遍历多个页面的不同作业的标题。当我运行脚本时,我可以注意到 selenium 无法打开该网页。但是,我可以在 Internet Explorer 或 Chrome 中手动使用该链接轻松查看该页面的内容。

网页链接 #如果看不到内容,请务必刷新页面

我试过:

from bs4 import BeautifulSoup
from selenium import webdriver

URL = 'https://www.alljobs.co.il/SearchResultsGuest.aspx?page=1&position=235,330,320,236,1541&type=&city=&region='

with webdriver.Chrome() as driver:
    driver.get(URL)
    soup = BeautifulSoup(driver.page_source,'lxml')

    while True:
        for item in soup.select('[class="job-content-top"]'):
            title = item.select_one('.job-content-top-title a[title')
            print(title)

        try:
            next_page = driver.find_elemeny_by_css_selector('.jobs-paging-next > a').click()
            soup = BeautifulSoup(driver.page_source,'lxml')
        except Exception:
            break
Run Code Online (Sandbox Code Playgroud)

我什至这样尝试过,但这也不起作用(从浏览器收集的 cookie):

from bs4 import BeautifulSoup
from selenium import webdriver

URL = 'https://www.alljobs.co.il/SearchResultsGuest.aspx?page=1&position=235,330,320,236,1541&type=&city=&region='

cookie = "_ga=GA1.3.1765365490.1582505881; _gid=GA1.3.568643527.1582505881; _fbp=fb.2.1582505881473.1930545410; _hjid=619e3a88-ee5a-43ca-8a0b-e70b063dcf84; BlockerDisplay=; DiplayPopUpSalarySurvey=; OB-USER-TOKEN=390dca4f-08d0-4f54-bce5-00e7e6aa3e39; LPVID=dkY2EwOTNmZTA4YTM1MDI1; …
Run Code Online (Sandbox Code Playgroud)

python selenium beautifulsoup web-scraping python-3.x

1
推荐指数
1
解决办法
282
查看次数

如何使用请求从网站上抓取不同职位的标题?

我正在尝试使用请求模块在 python 中创建一个脚本,以从网站上抓取不同工作的标题。要解析不同工作的标题,我需要首先从该站点获得相关响应,以便我可以使用 BeautifulSoup 处理内容。但是,当我运行以下脚本时,我可以看到该脚本产生的乱码实际上不包含我要查找的标题。

网站链接( In case you don't see any data, make sure to refresh the page)

我试过:

import requests
from bs4 import BeautifulSoup

link = 'https://www.alljobs.co.il/SearchResultsGuest.aspx?'

query_string = {
    'page': '1',
    'position': '235',
    'type': '',
    'city': '',
    'region': ''
}

with requests.Session() as s:
    s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
    s.headers.update({"Referer":"https://www.alljobs.co.il/SearchResultsGuest.aspx?page=2&position=235&type=&city=&region="})
    res = s.get(link,params=query_string)
    soup = BeautifulSoup(res.text,"lxml")
    for item in soup.select(".job-content-top [class^='job-content-top-title'] a[title]"):
        print(item.text)
Run Code Online (Sandbox Code Playgroud)

我什至这样试过:

import urllib.request …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping python-3.x python-requests

1
推荐指数
1
解决办法
498
查看次数

亚马逊使用 bs4、请求阻止了 Python 3 抓取

几天前,当我运行它时,此代码工作正常:

from bs4 import BeautifulSoup
import datetime
import requests

def getWeekMostRead(date):
    nonfiction_page = requests.get("https://www.amazon.com/charts/"+date.isoformat()+"/mostread/nonfiction")
    content = "amazon"+date.isoformat()+"_nonfiction.html"
    with open(content, "w", encoding="utf-8") as nf_file:
        print(nonfiction_page.content, file=nf_file)

    mostRead_nonfiction = BeautifulSoup(nonfiction_page.content, features="html.parser")

    nonfiction = mostRead_nonfiction.find_all("div", class_="kc-horizontal-rank-card")

    mostread = []
    for books in nonfiction:
        if books.find(class_="kc-rank-card-publisher") is None:
            mostread.append((
                books.find(class_="kc-rank-card-title").string.strip(),
                books.find(class_="kc-rank-card-author").string.strip(),
                "",
                books.find(class_="numeric-star-data").small.string.strip()
            ))
        else:
            mostread.append((
                books.find(class_="kc-rank-card-title").string.strip(),
                books.find(class_="kc-rank-card-author").string.strip(),
                books.find(class_="kc-rank-card-publisher").string.strip(),
                books.find(class_="numeric-star-data").small.string.strip()
            ))
    return mostread

mostread = []
date = datetime.date(2020,1,1)
while date >= datetime.date(2015,1,1):
    print("Scraped data from "+date.isoformat())
    mostread.extend(getWeekMostRead(date))
    date -= datetime.timedelta(7)
print("Currently saving scraped …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping python-3.x

1
推荐指数
1
解决办法
1277
查看次数